Last active
December 11, 2015 12:38
-
-
Save arundhaj/4601892 to your computer and use it in GitHub Desktop.
to perform file operation
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
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