Java FileReader, FileWriter & BufferedReader...

I have been tinkering around with Java's FileReader, FileWriter & BufferedReader; however, this time I will use screen shots to illustrate parts of the code instead of pasting it and formatting it to fit nicely. Extremely time consuming...not like this post will be quick either! So here we go...not sure if I am going to enjoy this post.

1) We instantiate the FileWriter
2) My output file will be "numbers.dat"



3) Write numbers from 1 to 100 separated by "," commas to the "numbers.dat" file



4) Close the FileWriter



5) Instantiate the FileReader



6) Instantiate the BufferedReader



7) Pass data from Buffer to textData variable



8) For Schnitz'N'Giggles for you (Beer Fest) bloaks, let's display all even numbers from 1-100 on the screen



9) Close Buffer



10) Instantiate a second FileWriter



11) Append all odd numbers from 1-100 to "numbers.dat"



12) Close the second FileWriter



13) Instantiate a second FileReader



14) Instantiate a second BufferedReader



15) Pass Buffered data to textData variable



16) Print results to screen



End Results...JOptionPane Window prompts

Create "numbers.dat" file prompt


Display even numbers prompt


Append odd numbers to "numbers.dat" prompt


Display final results prompt


Proof file was created!


Screen output! (Even numbers highlighted)


File data content! (Appended numbers highlighted)

0 comments: