How to create a file and write to a file in Java?
2380
16-Jul-2015
What's the simplest way to create and write to a (text) file in Java?
Anonymous User
17-Jul-2015public class Program {public static void main(String[] args) {
String text = "Hello world";
BufferedWriter output = null;
try {
File file = new File("example.txt");
output = new BufferedWriter(new FileWriter(file));
output.write(text);
} catch ( IOException e ) {
e.printStackTrace();
} finally {
if ( output != null ) output.close();
}
}
}