FileInputStream Vs. FileOutputStream

Java Input & Output Operations, Handling Flat Files, Handling Excel Files and handling Database Files. Read Input, Write output on the console, Read Files, Write Files, Compare Data and Manipulate File Data.
Post Reply
Posts: 142
Joined: Fri Nov 23, 2018 2:48 am

FileInputStream Vs. FileOutputStream

Post by AyubHussain » Thu Dec 06, 2018 7:02 am

What are FileInputStream and FileOutputStream?

Posts: 87
Joined: Fri Nov 23, 2018 5:29 am

Re: FileInputStream Vs. FileOutputStream

Post by manoj » Thu Dec 06, 2018 7:03 am

These two are general purpose classes used by the programmer very often to copy file to file. These classes work well with files containing less data of a few thousand bytes as by performance these are very poor.
For larger data, it is preferred to use BufferedInputStream (or BufferedReader) and BufferedOutputStream (or BufferedWriter).

Posts: 85
Joined: Thu Jan 03, 2019 3:58 am

Re: FileInputStream Vs. FileOutputStream

Post by srini » Fri Jan 04, 2019 11:56 am

This stream is used for reading data from the files.
Objects can be created using the keyword new and there are several types of constructors available.

InputStream f = new FileInputStream("C:/java/hello");

FileOutputStream is used to create a file and write data into it.
The stream would create a file, if it doesn't already exist, before opening it for output.

OutputStream f = new FileOutputStream("C:/java/hello")

Post Reply

Return to “Java IO & File Handling”