2021-12-17_学习B站Java基础视频_IO流(File概述)

P250:IO流(File概述)

import java.io.*;

class FileDemo {
    public static void main(String[] args) {
        consMethod();
    }

    // 创建File对象
    public static void consMethod() {
        // 将a.txt封装成File对象。可以将已有的和未出现的文件或者文件夹封装成对象
        // File f1 = new File("e:\\java1223\\day20\\abc\\a.txt");
        File f1 = new File("a.txt");

        File f2 = new File("e:\\java1223\\day20\\abc", "b.txt");

        File d = new File("e:\\java1223\\day20\\abc");
        File f3 = new File(d, "c.txt");

        sop("f1:" + f1);
        sop("f2:" + f2);
        sop("f3:" + f3);

        File f4 = new File("e:"+File.separator+"java1223"+File.separator+"d.txt");
        sop("f4:" + f4);
    }

    public static void sop(Object obj) {
        System.out.println(obj);
    }
}

 

posted on 2021-12-17 21:54  平凡力量  阅读(25)  评论(0编辑  收藏  举报