I am writing a program that has multiple users, and I want each user to be able to save a file with a filename they choose, but, also append their username or a related key to the file name to help with searching later on. How can I adjust this code to do so?
For example, the user “bob” wants to save a file as “aFile.html”. The file I want to actually save would be “aFile_bob.html”
String user = "bob";
// select a file to save output
JFileChooser JfileChooser = new JFileChooser(new File(defaultDirectory));
JfileChooser.setSelectedFile(new File("TestFile.html"));
int i = JfileChooser.showSaveDialog(null);
if (i != JFileChooser.APPROVE_OPTION) return;
File saveFile = JfileChooser.getSelectedFile();
// somehow append "user" to saveFile name here?
FileOutputStream fop = new FileOutputStream(saveFile);
Use the
renameTomethod, like this:Using this method, you don’t need the FileOutputStream.