Opening / Displaying Content of Text File in java

Tagged:  
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class OpenFile {

	public static void main(String[] args) throws IOException {

		String path = "/home/jr/Desktop/file1.txt";
                File file = new File(path);

		DataInputStream dis = new DataInputStream(                        new BufferedInputStream( new FileInputStream(file) ) );

		if( file.exists() )
			while (dis.available() != 0) 
				System.out.println(dis.readLine());
	        else	
			System.out.println(" file does not exist");

		dis.close();
	}
}

 

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
7 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.