Share on Google+Share on Google+

Java file DataInputStream

This section demonstrates you the use of DataInputStream class.

Java file DataInputStream

This section demonstrates you the use of DataInputStream class.

The class DataInputStream allows to read primitive Java data types from an underlying input stream. It reads the file line by line. In the given example, we have created an instance of DataInputStream class which wraps the FileInputStream. The method available() returns 0 if the file does not have more lines. The method readLine() reads the line from the file.

Here is the code:


public class FileDataInputStream {
	public static void main(String[] args) throws Exception {
		File file = new File("C:/data.txt");
		DataInputStream dis = new DataInputStream(new FileInputStream(file));
		while (dis.available() != 0) {

Through the above code, you can read any file using DataInputStream.



All glitters are not gold


Posted on: June 10, 2006 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.