Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import java.io.FileInputStream; public class Main { 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()); } } } |
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.