Skip to content

Instantly share code, notes, and snippets.

@Orange168
Created October 16, 2018 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Orange168/111e4f939cae53fff8ba39922b49e4b8 to your computer and use it in GitHub Desktop.
Save Orange168/111e4f939cae53fff8ba39922b49e4b8 to your computer and use it in GitHub Desktop.
[Java 读取写入文件M5等额外信息] #Java#md5#
static class RetryInfo {
String md5;
String times;
RetryInfo(String md5, String times) {
this.md5 = md5;
this.times = times;
}
static RetryInfo readRetryProperty(File infoFile) {
String md5 = null;
String times = null;
Properties properties = new Properties();
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(infoFile);
properties.load(inputStream);
md5 = properties.getProperty(RETRY_FILE_MD5_PROPERTY);
times = properties.getProperty(RETRY_COUNT_PROPERTY);
} catch (IOException e) {
TinkerLog.e(TAG, "fail to readRetryProperty:" + e);
} finally {
StreamUtil.closeQuietly(inputStream);
}
return new RetryInfo(md5, times);
}
static void writeRetryProperty(File infoFile, RetryInfo info) {
if (info == null) {
return;
}
File parentFile = infoFile.getParentFile();
if (!parentFile.exists()) {
parentFile.mkdirs();
}
Properties newProperties = new Properties();
newProperties.put(RETRY_FILE_MD5_PROPERTY, info.md5);
newProperties.put(RETRY_COUNT_PROPERTY, info.times);
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream(infoFile, false);
newProperties.store(outputStream, null);
} catch (Exception e) {
// e.printStackTrace();
TinkerLog.printErrStackTrace(TAG, e, "retry write property fail");
} finally {
StreamUtil.closeQuietly(outputStream);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment