Java获取下载文件的大小

Java获取下载文件的大小,第1张

可以直接通过>

文件夹的大小:

import javaioFile;

class DirDemo05{

public static void main(String[] args){

File src=new File("D:/Desktop/test/Stream");

printCount(src);

Systemoutprintln(count);

}

public static int count=0;

public static void printCount(File src){

//获取大小

if(null!=src && srcexists()){//递归头

if(srcisFile()){

count+=srclength();

}else{

for(File s:srclistFiles()){

printCount(s);

}

}

}

}

}

File file = new File("文件路径");

Systemoutprintln(filelength());//输出的是文件的字节数

这样就可以获得文件的长度了

import javaio;

import javautilzip;

/

  @author Hardneedl

 /

public class ZipEntriesDemo {

    public static void main(String args) throws IOException {

        ZipInputStream zipIn = new ZipInputStream(new FileInputStream(args[0]));

        ZipEntry zipEntry;

        while ( (zipEntry = zipIngetNextEntry()) != null ) {

            zipIncloseEntry();

            if (!zipEntryisDirectory()) {

                String name = zipEntrygetName();

                long size = zipEntrygetSize();

                long compd = zipEntrygetCompressedSize();

                Systemoutprintf("%s , size=%d, compressed size=%d\r\n", name, size, compd);

            }

        }

        zipInclose();

    }

}

以上就是关于Java获取下载文件的大小全部的内容,包括:Java获取下载文件的大小、在java中如何获取文件夹占用空间的大小、java.io.file对象中获取文件长度时 调用length方法 返回的是文件占用空间大小.如何获取文件自身的大小呢等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9496007.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存