import java.io.*;
import java.util.*;class FileExist
{
public static void main(String[] args)
{
File dir = new File("d:/1.txt");
if(dir.exists()) System.out.println("The file exist");
else System.out.println("The file is not exist");
}
}
import java.util.*;class FileExist
{
public static void main(String[] args)
{
File dir = new File("d:/1.txt");
if(dir.exists()) System.out.println("The file exist");
else System.out.println("The file is not exist");
}
}
{
return new File(filename).exists();
}
if(f.exists()){
....//存在
} else {
....//not exists
}
import java.util.*;class test
{
public static void main(String[] args)
{
File dir = new File("d:/1.txt");
if(dir.exists()) System.out.println("The file exist");
else System.out.println("The file is not exist");
}
}
会抛出FileNotFoundException的异常.
不过最好指定下名字,随便产生一个new可不是一个好习惯