Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从SD卡中查找任何文件的大小?_Android_File - Fatal编程技术网

Android 如何从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 =

我在SD卡中有一个
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等单位