File类
- 一个File类的对象,表示磁盘上的文件或目录,实际上,用FilePath(文件路径)对这个类来说是个更好的名字。
- File类没有指定信息怎么从文件读取或者向文件存储
先看File 的源代码
/**
* Creates a new <code>File</code> instance by converting the given
* pathname string into an abstract pathname. If the given string is
* the empty string, then the result is the empty abstract pathname.
*
* @param pathname A pathname string
* @throws NullPointerException
* If the <code>pathname</code> argument is <code>null</code>
*/
public File(String pathname) {
if (pathname == null) {
throw new NullPointerException();
}
this.path = fs.normalize(pathname);
this.prefixLength = fs.prefixLength(this.path);
}
创建文件实例:
public static void main(String[] args) {
File file = new File("D:/zheng.java");
try {
System.out.println(file.createNewFile());
} catch (IOException e) {
e.printStackTrace();
}
结果为
`true
Process finished with exit code 0`
并在D盘生zheng.java 文件