java判断文件是否存在?

如题所述

第1个回答  2013-09-22
用命令“文件是否存在”,如果该文件没有后缀名就用下面的代码,如果有后缀就把代码的“32156”改成带后缀的文件名:

.版本 2

.子程序 __启动窗口_创建完毕

.如果真 (文件是否存在 (取运行目录 () + “\32156”) = 假)
销毁 ()

.如果真结束
第2个回答  2013-12-26
public class FileUtils {
/**
* 检测网络资源是否存在 
*
* @param strUrl
* @return
*/
public static boolean isNetFileAvailable(String strUrl) {
InputStream netFileInputStream = null;
try {
URL url = new URL(strUrl);
URLConnection urlConn = url.openConnection();
netFileInputStream = urlConn.getInputStream();
if (null != netFileInputStream) {
return true;
} else {
return false;
}
} catch (IOException e) {
return false;
} finally {
try {
if (netFileInputStream != null)
netFileInputStream.close();
} catch (IOException e) {
}
}
}
}
第3个回答  2018-03-09
import java.io.File;

public class $ {

    public static void main(String[] args) {

        File f = new File("d:/a.txt");
        System.out.println(f.exists());
    }
}

false.不存在

true.存在

第4个回答  2012-02-17
public static void main(String[] args) {
if(new File("c:/test.txt").exists())
System.out.println("存在");
}
第5个回答  2014-01-13
if Dir("C:\a.txt") <> "" then
文件存在
end if