文件的判断

来源:互联网 发布:python入门经典pdf下载 编辑:程序博客网 时间:2024/06/05 03:39
/*文件的判断功能:
 * public boolean isDirectory()
 * public boolean isFile()
 * public boolean exists()
 * public boolean canRead()
 * public boolean canWrite()
 * public boolean isHidden()
 * 
 * */
import java.io.File;
import java.io.IOException;


public class FilePanduan {


public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
File file = new File("b.mp3");
System.out.println(""+file.createNewFile());
System.out.println("判断是否是文件的目录:"+file.isDirectory());
System.out.println("判断是否是文件:"+file.isFile());
System.out.println("判断文件是否存在:"+file.exists());
System.out.println("判断文件是否是可读的:"+file.canRead());
System.out.println("判断文件是否是可写的:"+file.canWrite());
System.out.println("判断文件是否是隐藏的:"+file.isHidden());

/*
* public String getAbsolutePath()
public String getPath()
public String getName()
public long length()
public long lastModified()


* */
System.out.println("获取的绝对路径:"+file.getAbsolutePath());  
System.out.println("获取的相对路径:"+file.getPath()); 
System.out.println("获取的名称:"+file.getName());
System.out.println("文件的字节数长度:"+file.length());
System.out.println("文件最后一次修改的时间:"+file.lastModified());

System.out.println("getCanonicalPath:"+file.getCanonicalPath());
System.out.println("getFreeSpace:"+file.getFreeSpace());
System.out.println("getParent:"+file.getParent());
System.out.println("getTotalSpace:"+file.getTotalSpace());
System.out.println("getUsableSpace:"+file.getUsableSpace());
System.out.println("length:"+file.length());
System.out.println("toString:"+file.toString());

}


}



0 0
原创粉丝点击