黑马程序员:java高级IO 1

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型
 }

}

你可能感兴趣的:(java,exception,IO,File,Path,import)