Maintain a checksum list on your server, download the file, generate a checksum of the downloaded file and check if it is the same as the one on the server. If it is, your file is fine.
How to check File integrity
Question
i'm developing an app that needs to download, every some minutes, some files.
Using php, i list all the files and from java i get this list and check for file if is present or not. Once downloaded it, i need to check for integrity because sometimes after the download, some files are corrupted.
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;
What can i use in php and java to check for file integrity?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow