/* program to read text from a file */
import java.io.*;
import java.io.FileWriter;
class FileReader
{
public static void main(String[] args)
{
try
{
File f=new File("E://NewFile.txt");
FileInputStream fs=new FileInputStream(f);
DataInputStream ds=new DataInputStream(fs);
String str;
while((str=ds.readLine())!=null)
{
System.out.println(str);
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
Output
sanjay kumar singh
File is present in the E:// Drive and the content is
import java.io.*;
import java.io.FileWriter;
class FileReader
{
public static void main(String[] args)
{
try
{
File f=new File("E://NewFile.txt");
FileInputStream fs=new FileInputStream(f);
DataInputStream ds=new DataInputStream(fs);
String str;
while((str=ds.readLine())!=null)
{
System.out.println(str);
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
Output
sanjay kumar singh
File is present in the E:// Drive and the content is
No comments:
Post a Comment