Welcome to the World of Online Learning:
Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Write a Java Program to Load File as InputStream
PROGRAM: Java Program to Load File as InputStream
/*Java Program to Load File as InputStream*/
1: Java Program to Load a Text File as InputStream
import java.io.InputStream;
import java.io.FileInputStream;
public class Main {
public static void main(String args[]) {
try {
// file input.txt is loaded as input stream
// input.txt file contains:
// This is a content of the file input.txt
InputStream input = new FileInputStream(“input.txt”);
System.out.println(“Data in the file: “);
// Reads the first byte
int i = input.read();
while(i != -1) {
System.out.print((char)i);
// Reads next byte from the file
i = input.read();
}
input.close();
}
catch(Exception e) {
e.getStackTrace();
}
}
}
2: Java Program to Load Java File as InputStream
import java.io.InputStream;
import java.io.FileInputStream;
public class Main {
public static void main(String args[]) {
try {
// file Test.java is loaded as input stream
InputStream input = new FileInputStream(“Time.java”);
System.out.println(“Data in the file: “);
// Reads the first byte
int i = input.read();
while(i != -1) {
System.out.print((char)i);
// Reads next byte from the file
i = input.read();
}
input.close();
}
catch(Exception e) {
e.getStackTrace();
}
}
}