IT

파일의 총 크기 (바이트) 가져 오기

lottoking 2020. 8. 11. 07:41
반응형

파일의 총 크기 (바이트) 가져 오기 [중복]


가능성이 : Java가 파일 크기를 처음으로 가져옵니다 .

에있는 파일 이름이라는 파일이 있습니다 E://file.txt.

FileInputStream fileinputstream = new FileInputStream(filename);

내가하고 싶은 것은 파일의 크기를 바이트 단위로 계산하는 것입니다. 어떻게 할 수 있습니까?


크기를 바이트 단위로 반환 하는 length()메서드를 사용할 수 있습니다 File.


파일 크기를 계산하기 위해 FileInputStream이 필요하지 않습니다 new File(path_to_file).length(). 또는 주장하는 경우 fileinputstream.getChannel().size().


.NET으로 간단하게 할 수 있습니다 .Files.size(new File(filename).toPath())


public static void main(String[] args) {
        try {
            File file = new File("test.txt");
            System.out.println(file.length());
        } catch (Exception e) {
        }
    }

참고 URL : https://stackoverflow.com/questions/14478968/get-total-size-of-file-in-bytes

반응형