public class Test03 {
public static void main(String[] args) throws IOException {
Scanner scan = new Scanner(System.in);
System.out.println("请输入文件名:");
String input = scan.nextLine().trim();
File file = new File("test.txt");
boolean flag = file.exists();
if (!flag) {//若不存在
file.createNewFile();
} else {
System.out.println("用户该目录已经存在");
int index = 0;
while (flag) {
index++;
file = new File("test_副本" + index + ".txt");
flag = file.exists();
}
file.createNewFile();
}
System.out.println("文件名:" + file.getName());
}
}