【发布时间】:2015-10-20 09:00:14
【问题描述】:
我有一小段代码
String fileName = "test.txt"
Path path = Paths.get(fileName);
File f = null;
if (Files.exists(path)) {
LOGGER.warn("File allready exists!");
f = new File("COPYOF-" + fileName);
} else {
f = new File(fileName);
}
它有效,但它没有做我想要它做的事情......
我想以“正确”的方式来做。
首次下载时,文件应命名为test.txt。第二次 - test(1).txt。第三个:test(2).txt 等
目前它正在以test.txt 的形式下载它,第二次将其命名为COPYOF-test.txt,而在第三次尝试时它只是覆盖了COPYOF-test.txt 文件。
我正在寻找一种适当的方法来实施此解决方案,但我不知道该怎么做...
【问题讨论】:
-
你能再添加一些代码吗,比如你调用它的函数。