s-day08- File介绍&File的构造方法
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package com.inmind.file01;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/*
|
||||
在java中定义了一个类File,用来表示计算机中的文件或文件夹.
|
||||
在英文中:
|
||||
File:文件
|
||||
Directory:目录,文件夹
|
||||
path:路径
|
||||
|
||||
File类表示文件或者文件夹,该类的使用场景:操作计算机中的文件或文件夹.在IO流中大量使用,文件下载文件上传等功能
|
||||
--------------------------------------------------------------------
|
||||
构造方法:
|
||||
file的构造方法:
|
||||
File(String pathname) 通过将给定的路径名字符串转换为抽象路径名来创建新的 File实例。
|
||||
File(String parent, String child) 从父路径名字符串和子路径名字符串创建新的 File实例。
|
||||
File(File parent, String child) 从父抽象路径名和子路径名字符串创建新的 File实例。
|
||||
*/
|
||||
public class FileDemo01 {
|
||||
public static void main(String[] args) {
|
||||
// File(String pathname) 通过将给定的路径名字符串转换为抽象路径名来创建新的 File实例。
|
||||
//File f = new File("D:\\io_test\\a.txt");
|
||||
File f = new File("D:/io_test/a.txt");
|
||||
System.out.println(f);
|
||||
|
||||
/*
|
||||
File(String parent, String child) 从父路径名字符串和子路径名字符串创建新的 File实例。
|
||||
parent:父路径 D:/io_test
|
||||
child:子路径 a.txt
|
||||
*/
|
||||
File f1 = new File("D:/io_test","a.txt");
|
||||
System.out.println(f1);
|
||||
|
||||
/*
|
||||
File(File parent, String child) 从父抽象路径名和子路径名字符串创建新的 File实例
|
||||
parent:父路径File对象 D:/io_test
|
||||
child:子路径 a.txt
|
||||
*/
|
||||
File parent = new File("D:/io_test");
|
||||
File f2 = new File(parent,"a.txt");
|
||||
System.out.println(f2);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user