Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

bufferedwriter bufferedreader java

public class FileIO {
  public static void main(String[] args) {
    String[] names = {"John", "Carl", "Jerry"};
    try {
      BufferedWriter writer = new BufferedWriter(new FileWriter("output.txt"));
      writer.write("Writing to a file.");
      writer.write("
Here is another line.");
      for (String name : names) {
        writer.write("
" + name);
      }
      writer.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
    
    try {
      BufferedReader reader = new BufferedReader(new FileReader("output.txt"));
      String line;
      while((line = reader.readLine()) != null) {
        System.out.println(line);
      }
      reader.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
 
PREVIOUS NEXT
Tagged: #bufferedwriter #bufferedreader #java
ADD COMMENT
Topic
Name
2+3 =