I'm trying to simple write a quick string to a text file using Java. However when doing so my code for some reason doesn't throw any errors or exceptions but the text file is empty after clicking the button. Here is my code
btnOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String text = textEntered.getText();
try{
PrintWriter out = new PrintWriter("~\\Users\\username\\Desktop\\File1.rft");
out.println(text);
out.close();
}catch(FileNotFoundException io){
System.out.println(io.getLocalizedMessage());
}
}
});
Some extra info, the username in my file path is my username I just swapped it out for this post.
Any help would be amazing, thanks a lot in advance.
C:\\Users\\username\\Desktop\\File1.rfttext.