1

I have the following code to read from a JSON file :

 public static void main (String[] args){
        JSONParser parser = new JSONParser();
        System.out.println("Reading JSON file ...");
        FileReader fileReader = new FileReader("data.json");
        JSONObject json = (JSONObject) parser.parse(fileReader);
        String timestamp = (String) json.get("time");
        String traces = (String) json.get("traces");
}

JSON file is in the class directory. I am getting FileNotFoundException

What am I doing wrong?

user207421
  • 305,947
  • 44
  • 307
  • 483
Mahsa
  • 1,502
  • 7
  • 18
  • 40
  • Can you please check data.json is available in JAVA_HOME directory. Otherwise give absolute path of data.json – Siva Kumar Oct 24 '15 at 20:26
  • 3
    The file isn't in the current working directory, simple as that. Your notion of 'current working directory' is probably flawed. Neither JAVA_HOME nor the project home have anything to do with it. – user207421 Oct 24 '15 at 23:49
  • [This](http://stackoverflow.com/a/19872017/2587435) might help your understanding – Paul Samsotha Nov 11 '15 at 00:19
  • Thank you I was able to solve the problem – Mahsa Nov 12 '15 at 16:37

0 Answers0