s-day08--File类获取的方法

This commit is contained in:
xx
2026-10-22 10:31:16 +08:00
parent 021d827235
commit a7541e0f00
+27
View File
@@ -0,0 +1,27 @@
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 Demo02 {
public static void main(String[] args) {
// File file = new File("D:\\io_test\\a1.txt");
File file = new File("D:\\io_test\\a");
System.out.println(file.getAbsolutePath());
System.out.println(file.getPath());
System.out.println(file.getName());
System.out.println(file.length());
}
}