Created
June 30, 2014 13:37
-
-
Save billy1380/bc1ea6723ae89973d0b0 to your computer and use it in GitHub Desktop.
Read and write .done files to mark long completion process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void writeDoneFile(String filePath) throws IOException { | |
String doneFilePath = filePath + ".done"; | |
FileOutputStream out = null; | |
try { | |
out = new FileOutputStream(doneFilePath); | |
out.write(SimpleDateFormat.getInstance().format(new Date()).getBytes()); | |
} finally { | |
if (out != null) { | |
out.close(); | |
} | |
} | |
} | |
public static Date doneAt(String filePath) throws IOException, ParseException { | |
String doneFilePath = filePath + ".done"; | |
Date date = null; | |
FileInputStream in = null; | |
try { | |
in = new FileInputStream(doneFilePath); | |
byte[] buffer = new byte[1024]; | |
int read = 0; | |
if ((read = in.read(buffer)) > 0) { | |
String content = new String(buffer, 0, read); | |
date = SimpleDateFormat.getInstance().parse(content); | |
} | |
} finally { | |
if (in != null) { | |
in.close(); | |
} | |
} | |
return date; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment