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"); } }