IO_File_路径常量_绝对与相对路径_构建对象JAVA143

来源:http://www.bjsxt.com/
一、S02E143_01IO_File、路径常量、绝对与相对路径、构建对象
1、I0概述
File类
IO流的原理及概念
IO流的分类
IO流类的体系
字节流和字符流
处理流
文件拷贝
文件分割与合并
File类:

package com.test.io.file;

import java.io.File;
/**
 * 两个常量
 * 1、路径分隔符  ;
 * 2、名称分隔符  \(windows)  /(linux等)
 */
public class Separator {

    public static void main(String[] args) {
        System.out.println(File.pathSeparator);//   ;
        System.out.println(File.separator);//   \
        //路径表示形式
        String path = "E:\\TEST\\A\\1.BMP";
        path = "E:" + File.separator + "TEST" + File.separator + "A" + File.separator + "1.BMP";
        //推荐方式
        path = "E:/TEST/A/1.BMP";
    }
}
package com.test.io.file;

import java.io.File;
/**
 * 相对路径与绝对路径构造File对象
 * File(File parent, String child)
 * File(String name)
 * File(String parent, String child)
 * File(URI uri) 
          通过将给定的 file: URI 转换为一个抽象路径名来创建一个新的 File 实例。
 */
public class Path {

    public static void main(String[] args) {
        String parentPath = "E:/TEST/A";
        String name = "1.BMP";
        //相对路径
        File src = new File(parentPath,name);//File(String parent, String child)
        System.out.println(src.getPath());
        System.out.println(src.getName());
        src = new File(new File(parentPath),name);//File(File parent, String child)
        System.out.println(src.getPath());
        System.out.println(src.getName());  
        //绝对路径
        src = new File("E:/TEST/A/1.BMP");//File(String name)
        System.out.println(src.getPath());
        System.out.println(src.getName());  
        //没有盘符: 以user.dir(当前工作空间)构建
        src = new File("test.txt");
        System.out.println(src.getPath());
        System.out.println(src.getName());
        System.out.println(src.getAbsolutePath());
    }
}
/*
返回:
E:\TEST\A\1.BMP
1.BMP
E:\TEST\A\1.BMP
1.BMP
E:\TEST\A\1.BMP
1.BMP
test.txt
test.txt
G:\Android学习\源代码\IO\test.txt
*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值