웹 사이트에서 파일을 다운로드하고 크기를 확인합니다 (운영 체제에서 크기를 바이트로 확인하면 동일).java 운영 체제와 파일 크기가 다른 이유
long size = Files.size(destFile.toPath())));
결과는 조작 system.Why에서 크기가 다른 :
connection.getContentLength();
int sizeBefore = connection.getContentLength();
BufferedInputStream bufferedInputStream = new BufferedInputStream(connection.getInputStream());
File destFile = new File(destFileName);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(
new FileOutputStream(destFile));
while ((i = bufferedInputStream.read()) != -1) {
bufferedOutputStream.write(i);
}
long sizeAfter = destFile.length();
bufferedOutputStream.flush();
bufferedInputStream.close();
if (sizeAfter == sizeBefore) {
log.debug("Downloaded file correct");
}
는 내가 다른 방법으로도 (NIO)으로 체크 저장된 파일을 tryed?
어떻게 다운로드하셨습니까? getContentLength가 더 컸습니까? 즉, 다운로드 코드를 검사해야한다는 의미 일 수 있습니다. FTP를 사용하면 CR/CRLF 변환이 발생할 수 있습니다. –
getContentLength()가 더 큽니다. – RomKazanova
필자는 아마 오해했을 지 모르지만 서면 파일을 닫으면 파일 크기를 차지합니까? 불충분 한 서면으로 작성 코드를보고 싶습니다. –