Program to Write in file using PrintWriter to in java





The PrintWriter class allows us to write formatted data into file. Rather than writing the byte value of data in file, it is written in format in which it is available to us.



Program to write in file using PrintWriter to in java >



import java.io.FileWriter;
import java.io.PrintWriter;
/** JavaMadeSoEasy.com */
public class WriteInFileUsingPrintWriter {
   public static void main(String...args) throws Exception {
          PrintWriter out = new PrintWriter(new FileWriter("c:/myFile.txt"));
          out.println("I am learning from JavaMadeSoEasy.com");
          out.close();
          System.out.println("content has been written in c:/myFile.txt");
         
   }
}
/* OUTPUT
content has been written in c:/myFile.txt
*/


RELATED LINKS>

Write String to file using FileOutputStream in java file IO


Write String to file using BufferedOutputStream (and FileOutputStream) in java file IO

Write String to file using BufferedWriter and FileWriter in java file IO

Program to Encrypt and decrypt text using password - Write encrypted text to file | Read encrypted text from file in java



eEdit
Must read for you :