I'm trying to read a file in java, when I run the program through the IDE it works fine but when it tries to open it when I execute the jar it says the file does not exist. Here is the code where it fails.
public class Main {
public static void main(String[] args) {
try {
App app = new App("files/" + "jsonFile.json", printWriter);
app.runApp();
} catch (Exception e) {
logger.error("error", e);
}
}
}
public class App {
public void runApp(){
File fileDescription = new File("./" + pathDescription);
StringBuilder allDescription = new StringBuilder();
try {
FileReader fr = new FileReader(fileDescription);
BufferedReader br = new BufferedReader(fr);
String line = "";
while ((line = br.readLine()) != null) {
allDescription.append(line);
}
JSONDescription = allDescription.toString();
fr.close();
br.close();
} catch (IOException e) {
logger.error("Error reading file",e);
}
}
}
I know the file exists inside the jar because I looked manually into the jar using jarzilla. Any idea of what it could be happening.