The total flow of the program lies in the fews steps written below.
- Create FileInputStream class object
- Get data size from FileInputStream
- Prepare byte (byte array) with the identified data size
- Read data from FileInputStream into byte
- Convert byte data into string
- Close FileInputStream
public class FileInput
public static void main(String args) throws Exception
FileInputStream fis= new FileInputStream("FileInput.java");
byte b=new byte[size];
String data=new String(b);
- The first statement is the import statement which can be clearly known.
- Then the FileInput class is created, under which in the main() method the FileInputStream class object is created in the 6th line.
- Then size is calculated in the 7th line by calling the available() method and byte is specified in the 8th line.
- Then by read() method the input is taken and then in the next line the byte data is converted to string.
- Then the output is shown by System.out.println() and then the FileInputStream is closed by close() method.
Well thats it. A simple program to print the source code in the output. You can give feedbacks in the comments below or you can contact me to my mail ID given in the profile.
Thanks for reading!
Latest posts by Bikash Panda (see all)
- Firmata protocol with Raspberry Pi and Arduino - September 13, 2017
- IOT:Power outlet controlled from internet using WeMOS - August 9, 2017
- OSMC on Raspberry PI with Setup and Control using Android App - July 7, 2017