Hi,
I’m hoping someone can help with a basic java question on reading a txt file on Windows. I’ve managed to write the txt file and am now trying to read it using the following method (where findPath is a method to get the url using java.net.URL url = getClass().getResource(testFile.txt);:-
public void readFromFile(String inFile)
{
FileReader fileReader;
BufferedReader reader;
String data;
try
{
fileReader = new FileReader(findPath(inFile));
reader = new BufferedReader(fileReader);
data = reader.readLine();
while (data != null)
{
System.out.println(data);
data = reader.readLine();
}
reader.close();
}
catch (IOException e)
{
System.out.println("Error in reading from file. " + e);
}
}
I’m getting an exception error telling me the file cannot be found giving the missing file details as:-
C:\Documents%20and%20Settings\My%20Doc... (The system cannot find the path specified)
The file does exist in this path, so why can’t my method find it? Is it something to do with my set up, or is it something else.
Thanks for your help in advance.
Tags: