数分ごとにいくつかのファイルをダウンロードする必要があるアプリを開発しています。
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で何を使用できますか?