Home »
» Viewing txt files on command prompt
Viewing txt files on command prompt
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
---------------
import java.io.*;
public class File1
{
public static void main (String[] args)
{
String file_name;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter file name eg: (d:\\test.txt) ");
try
{
file_name = br.readLine(); // getting file name from user
InputStream fileIn = new FileInputStream(file_name);
File ff = new File(file_name);
long lon_size = ff.length(); //getiing the length of the file
int buff_size = (int)lon_size;
System.out.println("Size of File " + lon_size);
byte buff[] = new byte[buff_size];
int i = fileIn.read(buff);
String s = new String(buff);
System.out.println(s);
}
catch(FileNotFoundException e)
{
System.out.println("File not found.");
}
catch(IOException e)
{
e.printStackTrace();
}
} //main
}//class
-----------------
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">