I'm new to java and currently trying to write some strings into a text file using this tut : http://www.homeandlearn.co.uk/java/write_to_textfile.html
so here is my code :
public void savefile() throws IOException {
JOptionPane.showMessageDialog(null,"Hi,i'm in Try Block :|");
FileWriter write = new FileWriter("asd.txt", true);
PrintWriter print = new PrintWriter(write);
JOptionPane.showMessageDialog(null, "File Opened");
write.write("Knock Knock");
print.flush();
print.write("Hello ?");
print.flush();
print.printf("Hi?");
print.flush();
print.println("anybody there?");
print.flush();
JOptionPane.showMessageDialog(null, "Can you hear me ?");
print.close();
JOptionPane.showMessageDialog(null, "File Closed");
}
and this is how I call the method:
try {
savefile();
}
catch (IOException e) {
JOptionPane.showMessageDialog(null, "Error: " + e.getMessage());
}
But nothing appears in the file! I'm really sick of this; what did I do wrong?