File Read
// File handling in java
// Read from file and display in terminal
import java.io.*;
class FileDisplay
{
public static void main(String as[]) throws IOException
{
FileInputStream fin = null;
int i;
try
{
fin = new FileInputStream("ipt.txt");
while(true)
{
i = fin.read();
if(i==-1)
break;
System.out.print((char)i);
}
System.out.println("File displayed successfully.");
}
catch(Exception e)
{
System.out.println(e);
}
finally
{
if(fin!=null)
fin.close();
System.out.println("End of pgm.");
}
}
}
No comments:
Post a Comment
Don't be a silent reader...
Leave your comments...
Anu