gpt4 book ai didi

java - 如果目录中存在文件名,则替换

转载 作者:行者123 更新时间:2023-11-29 05:54:27 26 4
gpt4 key购买 nike

这是我试过的代码。但是即使文件存在,这也会返回 false。变量 FilePath 和 FileName 从 UI 获取。

File exportFile = new File("\""+FilePath + "\\"+ FileName+"\"");  
boolean exists = exportFile.exists();

if (!exists) {

System.out.println("File does not exists");
}
else{

System.out.println( "File exists.");
}

执行此操作的正确方法是什么?顺便说一句,我如何提示用户替换或重命名文件名?

最佳答案

替换

File exportFile = new File("\""+FilePath + "\\"+ FileName+"\""); 

File exportFile = new File(FilePath + "\\" + FileName); 

不需要引用文件名。即使它包含空格。

关于java - 如果目录中存在文件名,则替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12708149/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com