268. Using FileInputStream I/O Class

Pre-requisite -

FileInputStream I/O Class need to be used only when we are not able to read any file using FileReader Class. So if not possible to read a file using FileReader Class, then go for FileInputStream Class.

As already explained you in my earlier posts that, the FileReader Class can be used to read text files without images etc, where as FileInputStream can read the files having images etc also. So if your files only contains text go with FileReader Class else go for FileInputStream Class.

Implementation of FileInputStream is similar to the FileReader Class. So instead of newly creating a class for FileInputStream implementation, lets edit the existing java class '' in our existing Java Project 'Project 51' as explained in the below steps -

1. Launch Eclipse IDE, open the existing Java Class '' from the 'Project 51' Java Project as shown below -

2. Replace above yellow highlighted FileReader Classes with FileInputStream Classes as shown below (Resolve import error)  -

3. Save & Run the program and observe that the text inside the 'xyz.txt' file got displayed in the output as shown below -

Hence the implementation part of FileInputStream I/O Class is same as FileReader I/O Class.

Please comment below to feedback or ask questions.

Using FileOutputStream I/O Class will be explained in the next post.

No comments:

Blog Index