首页 > 其他 > 详细

查询文件内容字节大小

时间:2019-12-27 18:50:36      阅读:102      评论:0      收藏:0      [点我收藏+]
public class Demo {

    public static void main(String[] args) throws ParseException, IOException {

        FileInputStream fileInputStream = new FileInputStream("D:\\Desktop\\aa.txt");
        System.out.println(contentLength(fileInputStream));

    }

    public static long contentLength(InputStream is) throws IOException {

        try {
            long size = 0;
            byte[] buf = new byte[256];
            int read;
            while ((read = is.read(buf)) != -1) {
                size += read;
            }
            return size;
        }
        finally {
            try {
                is.close();
            }
            catch (IOException ex) {
            }
        }
    }
}

查询文件内容字节大小

原文:https://www.cnblogs.com/yangxiaohui227/p/12109045.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!