FileWriter

  • Themenstarter Themenstarter Guest
  • Beginndatum Beginndatum
Status
Nicht offen für weitere Antworten.
G

Guest

Gast
Hallo,

hier ist ein kleines Programm, das 100mal "Text" in eine Datei schreibt:

Code:
public class vielText{

	
	public static Writer fw = null; 
	public static String s= "Textdatei.txt" ;
	
	
	public static void main(String[] args) throws IOException  {
		// TODO Auto-generated method stub
		
		
		
		
		for (int i = 0;i!=100;i++)
		{
			
		try 
		{ 
		  fw = new FileWriter(s); 
		  fw.write( "Text\n");
		} 
		catch ( IOException e ) { 
		  System.err.println( "Konnte Datei nicht erstellen" ); 
		} 
		
		finally { 
		  if ( fw != null ) 
		    try { fw.close(); } catch ( IOException e ) { } 
		}
		
		
		}

	}

}

Doch es steht nur eine Zeile Text in der Datei. Was mache ich falsch?
 
dein kleines Programm,
soll gleichzeitig heißen 'willst du noch eine Frage dazu stellen?'
 
Was ist daran falsch? Warum steht in meinet Datei nur eine Zeile Text und nicht 100?
 
Code:
ublic class vielText{

   
   public static Writer fw = null;
   public static String s= "Textdatei.txt" ;
   
   
   public static void main(String[] args) throws IOException  {
      // TODO Auto-generated method stub

      try
      {
           fw = new FileWriter(s);
           for (int i = 0;i<100;i++)
           {
                fw.write( "Text\n");
           }
           fw.close();
      }
      catch ( IOException e ) 
      {
          System.err.println( "Konnte Datei nicht erstellen" );
      }
     
   }

}

Jo, schon Cool^^

EDIT: Da steht nicht 100, weil du ja Text reinschreibst....
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben