import java.io.File;
public class Main {
public static void main(String[] args) {
String filePath = "/sdcard/wangrui.txt"; // 要读取的文件路径
File file = new File(filePath);
long sizeInBytes = file.length();
double sizeInKB = (double)sizeInBytes / 1024;
double sizeInMB = (double)sizeInBytes / (1024 * 1024);
System.out.println("文件大小为 " + sizeInBytes + " 字节");
System.out.println("文件大小为 " + sizeInKB + " KB");
System.out.println("文件大小为 " + sizeInMB + " MB");
}
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交