Cyr*_* N. 3 java corrupt download
我正在使用如何使用Java从Internet下载和保存文件这个很棒的片段?从网址下载文件:
URL website = new URL("http://www.website.com/information.asp");
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream("information.html");
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
Run Code Online (Sandbox Code Playgroud)
但是Long.MAX_VALUE,出于安全原因,我宁愿将下载限制为2mb,因此我将其替换为
fos.getChannel().transferFrom(rbc, 0, 2097152);
Run Code Online (Sandbox Code Playgroud)
但现在,我想知道如何处理文件大小超过2mb的情况?
我该怎么做才能检查文件是否损坏?