DataInputStream In Java Example

Chapter: Java I/O Last Updated: 21-07-2016 18:07:50 UTC

Program:

            /* ............... START ............... */
                
import java.io.DataInputStream;
import java.io.FileInputStream;

public class JavaDataInputStream {
	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());
		}

	}
}
                /* ............... END ............... */
        

Output

Welcome to JavaScan.com

Notes:

  • 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.

Tags

DataInputStream , Java, Java I/O

Similar Programs Chapter Last Updated
Hidden File Check In Java Example Java I/O 20-06-2016
FileWriter In Java Example Java I/O 21-07-2016
FileReader In Java Example Java I/O 21-07-2016
FileOutputStream In Java Example Java I/O 21-07-2016
FileInputStream In Java Example Java I/O 21-07-2016
DataOutputStream In Java Example Java I/O 21-07-2016
CharArrayWriter In Java Example Java I/O 13-04-2016
CharArrayReader In Java Example Java I/O 21-07-2016
ByteArrayOutputStream In Java Example Java I/O 21-07-2016
ByteArrayInputStream In Java Example Java I/O 21-07-2016
BufferedWriter In Java Example Java I/O 21-07-2016
BufferedReader In Java Example Java I/O 21-07-2016
BufferedOutputStream In Java Example Java I/O 21-07-2016
BufferedInputStream In Java Example Java I/O 21-07-2016
ProcessBuilder To Make System Calls In Java Java I/O 19-08-2017

1