I'm trying to read from a .txt
file that is located in src\main\java\props\engprops.txt
. I'm using backslashes here because I'm using Windows.
When I try to read the file I get a FileNotFoundException
.
This is my helper class. It contains a method for returning a string representation of the directory in which the file is located. Here is what it returns C:\Users\SOME_USER\workarea\Myapp\myapp\src\main\props\
private final static String APP_HOME = "\\workarea\\Translate\\translate\\src\\main";
private final static String PROPS_HOME = "\\props\\";
public static String getPropsPath() {
StringBuilder sb = new StringBuilder();
String userHome = System.getProperty("user.home");
//userHome = userHome.replace("\\", "/");
String propsHome = null;
propsHome = userHome + APP_HOME + PROPS_HOME;
return propsHome;
}
Then in my main class is where I try to read the file:
private static String stringPath = AppHelper.getPropsPath();
public static void main(String[] args) {
readFile();
}
public static void readFile() throws IOException {
FileReader fReader = new FileReader(stringPath + "engprops.txt");
BufferedReader bReader = new BufferedReader(fReader);
String line = null;
while((line = bReader.readLine()) != null) {
System.out.println(line);
}
bReader.close();
}
Inside the readFile()
method, I am appending the name of the file on to the stringPath
variable with the file name being engprops.txt
.
Here is a snippet of the console displays after the program executes; java.io.FileNotFoundException: C:\Users\600010209\workarea\Translate\translate\src\main\props\engprops.txt (The system cannot find the file specified)