Android 如何从SD卡中查找任何文件的大小?
我在SD卡中有一个Android 如何从SD卡中查找任何文件的大小?,android,file,Android,File,我在SD卡中有一个mp 3文件,我有那个mp 3/“任何扩展名”文件的路径 现在, 如何使用代码获取mp 3文件的大小?试试这个 File file=new File(Environment.getExternalStorageDirectory(), "lala.mp3"); if(file.exists()){ double bytes = file.length(); double kilobytes =
mp 3
文件,我有那个mp 3/“任何扩展名”文件的路径
现在,
如何使用代码获取mp 3文件的大小?试试这个
File file=new File(Environment.getExternalStorageDirectory(), "lala.mp3");
if(file.exists()){
double bytes = file.length();
double kilobytes = (bytes / 1024);
double megabytes = (kilobytes / 1024);
double gigabytes = (megabytes / 1024);
double terabytes = (gigabytes / 1024);
double petabytes = (terabytes / 1024);
double exabytes = (petabytes / 1024);
double zettabytes = (exabytes / 1024);
double yottabytes = (zettabytes / 1024);
System.out.println("bytes : " + bytes);
System.out.println("kilobytes : " + kilobytes);
System.out.println("megabytes : " + megabytes);
System.out.println("gigabytes : " + gigabytes);
System.out.println("terabytes : " + terabytes);
System.out.println("petabytes : " + petabytes);
System.out.println("exabytes : " + exabytes);
System.out.println("zettabytes : " + zettabytes);
System.out.println("yottabytes : " + yottabytes);
}else{
System.out.println("File does not exists!");
}
试试这个
File filenew = new File(selectedPath);
int file_size = Integer.parseInt(String.valueOf(filenew.length()/1024));
并检查一下这个例子
请尝试以下代码:
File file = new File(PATH OF YOUR FILE);
long fileSize = file.length();
在此之后,您可以对大小执行任何操作,这意味着这些数据将以字节为单位。您可以将其转换为KB、MB、GB等单位