Java:Criando um arquivo em Java

From Wiki
Revision as of 21:58, 28 February 2008 by Ebasso (talk | contribs)

Gravando um arquivo em Java

import java.io.*;

/**
* @author ebasso
*/
public class GravaArquivo {

 public static void main(String[] args) {
   FileOutputStream saida;
   PrintStream fileSaida;
   String sI = "";
   try {
     saida = new FileOutputStream("meuarquivo.txt");
     fileSaida = new PrintStream(saida);

     for (int i = 1; i < 10; i++) {
       sI = String.valueOf(i);
       fileSaida.println(sI);
     }
   }
   catch (Exception e){
     System.err.println(e);
   }
 }
}