Hi I am trying to write a file writer inside my mouse event code. I am trying to use the file name that comes from JTextField and write it into a file.
Here is my code:-
private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.showSaveDialog(this);
chooser.getSelectedFile();
File selectedPfile = chooser.getSelectedFile();
jTextField1.setText(selectedPfile.getAbsolutePath());
String text = jTextField1.getText();
try {
PrintWriter dataOut = new PrintWriter(new FileWriter("TEXT.txt"), true);
dataOut.println(text);
dataOut.close();
}
catch(IOException e) {}
}
Thanks