file and IO (1)

9/28 clock in!

one:flie path

1.absolute path

2.relative path

if ensure a reference path,how find it's absolute path?

describe:    ./  /  /

what is ../

 

 3.work catalogue

 two:file create

 1.first situation:

public class IO {
    public static void main(String[] args) throws IOException {
        File file=new File("C:/test.txt");
        System.out.println(file.getParent());//父目录文件路径
        System.out.println(file.getName());//纯文件name
        System.out.println(file.getPath());//single path name
        System.out.println(file.getAbsoluteFile());
        System.out.println(file.getCanonicalFile());

    }
}

 

2.second situation

we are using the IDEA,so the work catalogue is the directory of the open project.

public class IO {
    public static void main(String[] args) throws IOException {
        File file=new File("./test.txt");
       
        System.out.println(file.getParent());//父目录文件路径
        System.out.println(file.getName());//single file name
        System.out.println(file.getPath());//single path name
        System.out.println(file.getAbsoluteFile());
        System.out.println(file.getCanonicalFile());

    }
}

3. phe no me non

 the "test.txt" was not found to exist,but if not find out,able to create it 

public class IO {
    public static void main(String[] args) throws IOException {
        File file=new File("./test.txt");
        System.out.println(file.exists());
        System.out.println(file.isFile());
        System.out.println(file.isDirectory());
        file.createNewFile();
        System.out.println(file.exists());
        System.out.println(file.isFile());
        System.out.println(file.isDirectory());

    }
}

 

 Three:file delete

 Four:create file's catalogue

 1.create single-deck catalogue  

2.create multideck catalogue 

public class IO {
    public static void main(String[] args) throws IOException {
        //File file=new File("./test.txt");
        //file.mkdir();
        File file=new File("./test.txt/aaa/bbb");
        file.mkdirs();
    }
}

 

3. list file

public class IO {
    public static void main(String[] args) throws IOException {
 
        File file=new File("./test");
       String[] result = file.list();
        System.out.println(Arrays.toString(result));
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值