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

来源:互联网 发布:win10 网络唤醒端口 编辑:程序博客网 时间:2024/05/03 09:08

来源: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.BMP1.BMPE:\TEST\A\1.BMP1.BMPE:\TEST\A\1.BMP1.BMPtest.txttest.txtG:\Android学习\源代码\IO\test.txt*/
0 0
原创粉丝点击