Skip to content

Instantly share code, notes, and snippets.

@arundhaj
Last active December 11, 2015 12:38
Show Gist options
  • Save arundhaj/4601892 to your computer and use it in GitHub Desktop.
Save arundhaj/4601892 to your computer and use it in GitHub Desktop.
to perform file operation
File f = new File("helloworld.txt")
FileOutputStream fos = new FileOutputStream(historyFile, true)
DataOutputStream dos = new DataOutputStream(fos)
BufferedWriter bw = new BufferedWriter((new OutputStreamWriter(dos)))
Date today = new Date()
for(int i = 10; i >= 0; i--) {
Date anotherDay = new Date()
anotherDay.date = today.date + i;
bw.writeLine(anotherDay.format(dateFormat) + "," // Date
+ Math.round( Math.random() * 100 )) // Random number
}
bw.flush()
dos.close()
FileInputStream fio = new FileInputStream(historyFile)
DataInputStream dis = new DataInputStream(fio)
BufferedReader br = new BufferedReader(new InputStreamReader(dis))
String strLine;
while ((strLine = br.readLine()) != null) {
logger.info(strLine);
}
dis.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment