热心网友
回答时间:2022-06-17 08:19
android中的java获取文件大小的方法:
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
public class FileContent {
private String path = "F:\\下载说明.txt";
public FileContent() throws IOException
{
File f = new File(path);
FileReader fileReader = new FileReader(f);
BufferedReader br = new BufferedReader(fileReader);
String str;
while((str = br.readLine() ) != null)
{
System.out.println(str);
}
System.out.println(new FileInputStream(new File(path)).available() / 1024 / 1024 +"M");
}
public static void main(String[] args) {
try {
new FileContent();
} catch (IOException e) {
e.printStackTrace();
}
}
}
收起