查询文件内容字节大小
Posted yangxiaohui227
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了查询文件内容字节大小相关的知识,希望对你有一定的参考价值。
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) { } } } }
以上是关于查询文件内容字节大小的主要内容,如果未能解决你的问题,请参考以下文章