AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-file-handling: What is the difference between FileOutputStream and FileWriter?

Explain the difference between FileOutputStream and FileWriter?

corejava x 353
file-handling x 9
Posted On : 2014-09-13 01:22:53.0
profile Saksham Kumar - anyforum.in Saksham Kumar
73433939909
up-rate
2
down-rate

Answers


From Java API Specification:
------------------------------------------------------------
FileOutputStream is used for writing streams of raw bytes such as image data. For writing streams of characters, we should go with FileWriter.


Using FileOutputStream:
----------------------------------------------------------
File fout = new File(file_location_string);
FileOutputStream fos = new FileOutputStream(fout);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(fos));
out.write("something");


Using FileWriter:
---------------------------------------------
FileWriter fstream = new FileWriter(file_location_string);
BufferedWriter out = new BufferedWriter(fstream);
out.write("something");

Both will work, There are a lot of discussion on each of those classes, they both are good implements of file i/o concept that can be found in a general operating systems. However, we don?t care how it is designed, but only how to pick one of them and why pick it that way.

Posted On : 2014-09-13 01:45:38
Satisfied : 1 Yes  1 No
profile Garima Gupta - anyforum.in Garima Gupta
596129560202
Reply This Thread
up-rate
4
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in