import java.io.*;
import java.sql.Date;
/**
*
*/
/**
* @author cui
*
*/
public class filetest {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
File f= new File("1.txt");
if(f.exists())
{
f.delete();
}
else
{
try {
f.createNewFile();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
System.out.println("File Name:"+f.getName());
System.out.println("File Path:"+f.getPath());
System.out.println("File CanonicalPath:"+f.getCanonicalPath());//规范的路径格式显示
System.out.println("File abs path:"+f.getAbsolutePath()); //绝对路径
System.out.println("File Parent:"+f.getParent()); //所在的上级目录
System.out.println(f.exists()?"exists":"not exists");
System.out.println(f.canRead()?"read":"not read");
System.out.println(f.isDirectory()?"directory":"not diretory");//是否是目录
System.out.println("File last modified:"+new Date(f.lastModified())); //lastModified返回long型
}
}