I was offered this code to solve one of my problems:
private static final String PATH_FMT =
"C:\\Users\\{0}\\Desktop\\Bloomberg Rechnung-{1,date,yyyyMMdd}{2,choice,0< ({2})}.xlsx";
private File save() throws IOException {
Date now = new Date();
for (int fCounter = 0; ; fCounter++) {
Path path = Paths.get(
MessageFormat.format(PATH_FMT, this.username, now, fCounter)
);
try (OutputStream out = Files.newOutputStream(path, CREATE_NEW)) {
this.wb.write(out);
this.wb.close();
return path.toFile();
} catch (FileAlreadyExistsException incrCounterAndRetry) {
}
}
}
Unfortunately, this code does not fully fulfill what I want. He should create a file. The first file that it should create without another file with the name should not have a counter. The second file that is created must have a counter in the file name (no matter where it starts). I am currently getting the file with the counter 0 as the first file. Can someone help me fix this problem? And maybe someone can explain to me how it works {2,choice,0< ({2})}.
Thanks in advance
source
share