try
{
BufferedReader br = new BufferedReader(new FileReader("MyFile.txt"));
String line = br.readLine();
}
catch(FileNotFoundException fnfe)
{
System.out.println("File MyFile.txt not found.");
}
catch(IOException ioe)
{
System.out.println("Unable to read from MyFile.txt");
}
The code previously suggested will only get you the first line. Try this instread:
try
{
BufferedReader br = new BufferedReader(new FileReader("MyFile.txt"));
StringBuffer line = new StringBuffer();
String temp = null;
while( ( temp = br.readLine() ) != null )
{
line.append( temp );
}
// Then use line.toString() to convert to a String.
}
catch(FileNotFoundException fnfe)
{
System.out.println("File MyFile.txt not found.");
}
catch(IOException ioe)
{
System.out.println("Unable to read from MyFile.txt");
}