FileWriter class

                                           
    java.lang.Object                                      
     |                                     
     |--java.io.Writer                                  
         |                                 
         |--java.io.OutputStreamWriter                              
             |                             
             |--java.io.FileWriter                          
                                           

FileWriter is for writing streams of characters.

ConstructorSummary
FileWriter(File file)Creates a FileWriter object given a File object.
FileWriter(File file, boolean append)Creates a FileWriter object given a File object.
FileWriter(FileDescriptor fd)Creates a FileWriter object associated with a file descriptor.
FileWriter(String fileName)Creates a FileWriter object given a file name.
FileWriter(String fileName, boolean append)Creates a FileWriter object given a file name with a boolean indicating whether or not to append the data written.

Methods inherited from class java.io.OutputStreamWriter

ReturnMethodSummary
voidclose()Closes the stream, flushing it first.
voidflush()Flushes the stream.
StringgetEncoding()Returns the name of the character encoding being used by this stream.
voidwrite(char[] cbuf, int off, int len)Writes a portion of an array of characters.
voidwrite(int c)Writes a single character.
voidwrite(String str, int off, int len)Writes a portion of a string.
Revised from Open JDK source code

  import java.io.FileWriter;

public class Main {
  public static void main(String args[]) throws Exception {
    FileWriter fw = new FileWriter(args[0]);
    for (int i = 0; i < 12; i++) {
      fw.write("Line " + i + " java2s.com \n");
    }
    fw.close();
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.