Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import java.io.DataInputStream; import java.io.FileInputStream; public class Main { public static void main(String[] args) { try { FileInputStream fis = new FileInputStream("Javafile.txt"); DataInputStream stream = new DataInputStream(fis); char c; while (stream.available() > 0) { c = (char) stream.read(); System.out.print(c); } stream.close(); fis.close(); } catch (Exception ex) { System.out.println(ex.getMessage()); } } } |
The Java.io.DataInputStream class lets an application read primitive Java data types from an underlying input stream in a machine-independent way.
An application uses a data output stream to write data that can later be read by a data input stream.
DataInputStream is not necessarily safe for multithreaded access. Thread safety is optional and is the responsibility of users of methods in this class