I'm trying to read in a text file character by character. However, when I try to read it in it using the readChar method in DataInputStream it gives me a IOException. Heres what I have so far
FileInputStream stream;
try
{
// Open an input stream
stream = new FileInputStream ("test");
// Read a line of text
DataInputStream input = new DataInputStream (stream);
try //tries to read input file
{
c=input.readChar();
s="char" + c;
}
catch (NullPointerException e)
{
System.out.print("");
}
// Close our input stream
stream.close();
}
// Catches any error conditions
catch (IOException e) //This is the Exception that gets thrown
{
System.err.println ("Unable to read from file");
System.exit(-1);
}
System.out.println(s);
My text file "test" simply has "i" in it.
Hope someone can tell me why this exception is thrown. Do I have to do something differently from the readLine()?