Guest User

Buffered Writer Example

a guest
Dec 22nd, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. import java.io.*; //imports the Buffered Writer
  2.  
  3. public class main{ //main
  4.   public static void main(String[] args)throws IOException{
  5.       Writer output = null; //initializes the Writer
  6.       String text = "Example Write";  //Used for an example of how to write to file.
  7.       File file = new File("write.txt"); //creates a file with the file name using the object "file"
  8.       output = new BufferedWriter(new FileWriter(file)); //creates a buffered writer called output
  9.       output.write(text); //uses the output object to write the example text to file.
  10.       output.close(); //clearing memory and closing file.
  11.  
  12.       System.out.println("Your file has been written"); //Unimportant
  13.   }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment