s-day08- File类获取的方法
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
package com.inmind.file01;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/*
|
||||||
|
File类的获取方法
|
||||||
|
public String getAbsolutePath() :返回此File的绝对路径名字符串。(重点)
|
||||||
|
public String getPath() :将此File转换为路径名字符串。(了解)
|
||||||
|
public String getName() :返回由此File表示的文件或目录的名称。(重点)
|
||||||
|
public long length() :返回由此File表示的文件的长度。
|
||||||
|
|
||||||
|
注意:
|
||||||
|
1.对于length只能来获取文件的大小,而不能获取文件夹的大小.
|
||||||
|
2.在UTF-8编码方式中,一个中文占3个字节
|
||||||
|
在GBK编码方式中,一个中文占2个字节
|
||||||
|
*/
|
||||||
|
public class FileDemo02 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//获取本地D盘的文件对象
|
||||||
|
File f = new File("D:/io_test/a.txt");
|
||||||
|
// File f = new File("D:/io_test/upload");
|
||||||
|
|
||||||
|
System.out.println(f.getAbsolutePath());//绝对路径:D:\io_test\a.txt
|
||||||
|
System.out.println(f.getPath());//传入的路径内容是什么,就是什么
|
||||||
|
System.out.println(f.getName());//文件或目录的名称
|
||||||
|
System.out.println(f.length());//文件的大小(字节数)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user