File

package Z3_3;

import java.io.File;
import java.io.IOException;

public class IO {
public static void main(String[] args) throws IOException, Exception{
    //file 类,帮助咱们操做电脑磁盘上的真实文件
    File file=new File("src/hello.txt");//建立一个文件对象
    if(file.exists()){//是否存在
        file.delete();//删除文件
    }
    else{
        file.createNewFile();//建立文件
        System.out.println("建立hello成功");
    }
    System.out.println("查看5714.txt");
    File file1=new File("src/5714.txt");//建立一个文件对象
    if(file1.isDirectory())    {//判断是不是目录
        System.out.println("不是文件,是目录");
        
    }
    else if(file1.isFile()){//判断是不是文件
        System.out.println("大小"+file1.length());
        System.out.println("名称"+file1.getName());
        System.out.println("绝对路径"+file1.getAbsolutePath());
        System.out.println("相对路径"+file1.getPath());
    }
    else{
        System.out.println("不存在");
    }
    
    /*************************************************************/
//    FileIputStream fileObject=new FileIputStream("src/5714.txt");
}
}
相关文章
相关标签/搜索