Changes

Jump to navigation Jump to search
651 bytes added ,  20:59, 3 April 2015
Line 408: Line 408:     
}
 
}
 +
}</source>
 +
 +
=== Writing files ===
 +
<source lang="java">
 +
import java.io.BufferedWriter;
 +
import java.io.File;
 +
import java.io.FileNotFoundException;
 +
import java.io.FileWriter;
 +
import java.io.IOException;
 +
 +
public class WritingFiles {
 +
 +
public static void main(String[] args) {
 +
File file = new File("./src/tutorialJava/textFile2.txt");
 +
 +
try (BufferedWriter br = new BufferedWriter(new FileWriter(file))) {
 +
br.write("This is line 1");
 +
br.newLine();
 +
br.write("This is line 2");
 +
br.newLine();
 +
br.write("Last line");
 +
br.newLine();
 +
 +
} catch (IOException e) {
 +
System.out.println("Unable to read the file: " + file.toString());
 +
}
 +
 +
}
 +
 
}</source>
 
}</source>
  

Navigation menu