Java文件存在下划线
我正在努力解决这个问题。搜索时,由于文件名中存在下划线,我无法找到该文件
File file = new File(filePath + "file_2.exe");
if (file.exists()){
System.out.println("File found");
}else{
System.out.println("File not found");
}
,但我需要将其保留,请问有什么想法吗?
感谢您提前提供帮助。 :)
I'm trying to solve this issue. When searching I'm not able to find the file due to the underscore in the file name
File file = new File(filePath + "file_2.exe");
if (file.exists()){
System.out.println("File found");
}else{
System.out.println("File not found");
}
but I need to leave it in, any ideas please?
Thanks for you help in advance. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用
new File(filePath, "file_2.exe")
— 注意两个参数并且缺少+
。也许您只是在
filePath
末尾缺少一个反斜杠。Try using
new File(filePath, "file_2.exe")
— note two arguments and absence of the+
.Maybe you're just missing a backslash at the end of
filePath
.提供 filePath 变量的值和该程序的输出。文件路径可能有问题,因为使用的是反斜杠而不是正斜杠。
provide the value of filePath variable and output of this program. There may be problem with the filePath, becuase of backslash instead of forward slash.
请注意粗体行中的错误,'+' 被替换为 ','
File file = new File(filePath, "file_2.txt");
package Stackoverflow;
Note the error in the line in Bold, '+' is replaced with ','
File file = new File(filePath, "file_2.txt");
package Stackoverflow;