Create files with similar names using Java without overwriting existing file
java
Solution
i want to know if there are any native java commands to stop overwriting [and append a numeral to the filename]
Not in the core Java libraries, no.
Problem
I was wondering if it is possible to create multiple files with similar names, without overwriting the current file. for example: if I have a file: xyz.txt next time when i create it should be : xyz(1).txt ``` try { File makefile = new File("output.txt"); FileWriter fwrite = new FileWriter(makefile); fwrite.write("example file"); fwrite.flush(); fwrite.close(); } catch (IOException e) { e.printStackTrace(); } ``` so if I re-run this program my current file should not be overwritten. I have already tried and if condition with a flag variable to add number as prefix to the file name. I want to know if there are any Java commands to avoid overwriting an existing file.