public class Test02 {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个文件名:");
String name = sc.nextLine();
File file = new File("E:\\upload",name);
int i = 0;
boolean exists = file.exists();
if (!exists) {
file.createNewFile();
System.out.println("文件创建成功");
}else {
System.out.println("该文件已存在!");
// 截取文件名
String word = name.substring(0,name.indexOf("."));
while (exists){
i++;
file=new File("E:\\upload",word+"_副本"+i+".txt");
exists = file.exists();
}
file.createNewFile();
System.out.println("文件副本创建成功");
}
}
}
07-16
1510
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交