Sunday, September 28, 2008

READ A FILE

/* Java Program to read a file and display it on the screen */
import java.io.*;
public class LioFile
{
public static void main(String args[])
{
try
{
FileReader fr=new FileReader("LioFile.java");
BufferedReader br=new BufferedReader(fr);
String str=" ";String s1 =" ";
System.out.println(" s1 is "+s1.equals("ass"));
while((str=br.readLine())!=null)
{
System.out.println(str);
}
}
catch(FileNotFoundException fe)
{
fe.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
/**** Output ***
s1 is false
import java.io.*;
public class J7
{
public static void main(String args[])
{
try
{
FileReader fr=new FileReader("J7.java");
BufferedReader br=new BufferedReader(fr);
String str=" ";String s1 =" ";
System.out.println(" s1 is "+s1.equals("ass"));
while((str=br.readLine())!=null)
{
System.out.println(str);
}
}catch(FileNotFoundException fe)
{f
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}*/

No comments: