[英]How to check File integrity
我正在开发一个需要每隔几分钟下载一些文件的应用程序。
使用php,我列出所有文件,从java我得到这个列表并检查文件是否存在。 下载后,我需要检查完整性,因为有时在下载后,某些文件已损坏。
try{
String path = ...
URL url = new URL(path);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.setReadTimeout(30000);
is = conn.getInputStream();
ReadableByteChannel rbc = Channels.newChannel(is);
FileOutputStream fos = null;
fos = new FileOutputStream(local);
fos.getChannel().transferFrom(rbc, 0, 1 << 24);
fos.close();
rbc.close();
} catch (FileNotFoundException e) {
if(new File(local).exists()) new File(local).delete();
return false;
} catch (IOException e) {
if(new File(local).exists()) new File(local).delete();
return false;
} catch (IOException e) {
if(new File(local).exists()) new File(local).delete();
return false;
}
return false;
我可以在php和java中使用什么来检查文件完整性?
维护服务器上的校验和列表 ,下载文件, 生成下载文件的校验和,并检查它是否与服务器上的文件相同。 如果是,你的档案没问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.