import java.io.File;
public class File_Stu {
public static void main(String[] args) {
File file = new File("C:\\Users\\BO\\Desktop", "www.txt");
if (! file.exists()) {//不存在
try {
boolean isCreat = file.createNewFile();
if (isCreat) {
System.out.println("文件不存在,但是创建成功了");
}else{
System.out.println("文件创建失败");
}
} catch (Exception e) {
System.out.println(e.getMessage());
// TODO: handle exception
}
}else{//文件已经存在的状态...
System.out.println("文件是否可读:"+file.canRead());
System.out.println("文件是否可写:"+file.canWrite());
System.out.println(file.getName() +"的长度是"+file.length());
}
}
}
网友评论