[Solved] File Name defined by user in Java [closed]


You need a method to get the name from the user. I presume you have that. And you need a folder within which to save the files (unless you want the user to specify folder as well).

When users enter file names, they might type characters that are not allowed in file names. You must scan the characters and sanitize what they type, otherwise the file creation will fail.

File   folder           = new File("/put/the/desired/path/here/");
String fileNameFromUser = methodToGetFilename();
       fileNameFromUser = cleanBadCharacters(fileNameFromUser);
File   theFile          = new File(folder, fileNameFromUser + ".aaa");

now you can open, read, or write, the file specified by the user. Note that the variable folder is defined by you, either a string path, or another File variable.

4

solved File Name defined by user in Java [closed]