查询文件内容字节大小

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

猜你喜欢

转载自www.cnblogs.com/yangxiaohui227/p/12109045.html