import java.io.File;
public class FileTest {
public static void main(String[] args) {
File f = new File("e://abc","User.java");
fileInfo(f);
}
public static void fileInfo(File f){
System.out.println("文件名:" + f.getName());
System.out.println("路径:" + f.getPath());
System.out.println("父路径:" + f.getParent());
System.out.println("绝对路径:" + f.getAbsolutePath());
if(f.exists()){
System.out.println("文件存在");
System.out.println("是目录?" + f.isDirectory());
System.out.println("可读?" + f.canRead());
System.out.println("可写?" + f.canWrite());
System.out.println("文件的长度为:" + f.length());
System.out.println("文件最后被修改的日期:" + f.lastModified());
}
if(f.delete()){
System.out.println(f.exists()? "删除失败" : "删除成功");
}
}
}
【流】File类
最新推荐文章于 2024-08-11 15:48:58 发布