码迷,mamicode.com
首页 > 其他好文 > 详细

查询文件内容字节大小

时间:2019-12-27 20:18:32      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:string   demo   system   stat   puts   out   parse   style   finally   

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) {
            }
        }
    }
}

查询文件内容字节大小

标签:string   demo   system   stat   puts   out   parse   style   finally   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!