我正在开发一个需要每隔几分钟下载一些文件的应用。
我使用 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 中使用什么来检查文件完整性?
最佳答案
维护 checksum list on your server , 下载文件, generate a checksum of the downloaded file并检查它是否与服务器上的相同。如果是,则您的文件没有问题。
关于php - 如何检查文件完整性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16118463/