FileInputStream In Java Example
Chapter:
Java I/O
Last Updated:
21-07-2016 18:12:23 UTC
Program:
/* ............... START ............... */
import java.io.FileInputStream;
public class JavaFileInputStream {
public static void main(String[] args) {
try {
FileInputStream stream = new FileInputStream("Javafile.txt");
while (stream.available() > 0) {
System.out.print((char) stream.read());
}
stream.close();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}
/* ............... END ............... */
Notes:
-
The Java.io.FileInputStream class obtains input bytes from a file in a file system.
- FileInputStream(File file) - creates a FileInputStream by opening a connection to an actual file, the file named by the File object file in the file system.
- FileInputStream(FileDescriptor fdObj) - creates a FileInputStream by using the file descriptor fdObj, which represents an existing connection to an actual file in the file system.
- FileInputStream(String name) - creates a FileInputStream by opening a connection to an actual file, the file named by the path name name in the file system.
Tags
FileInputStream , Java, Java I/O