本文介绍了Java File.exists()即使文件不存在也返回true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

String filePath = "C:\Users\d654227/Desktop/abdc.url"; // Actually its getting constructed dynamically.

File file = new File(filePath);
if(file.exists()){
       LogUtil.logConsole(filePath+" File already exist.");
        file.delete();
}else
{
        LogUtil.logConsole(filePath+" File doesnt exist.");
}

推荐答案

尝试使用所有'/'编写路径.而且注意的是String不是Sting.

Try writing your path with all '/'.And notice is String not Sting.

这篇关于Java File.exists()即使文件不存在也返回true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 17:42