I'm making a maven project and I'm trying to use Gson or simpleJson as a parser for my project.
I have a file called moves.json in my resource folder and when I'm trying to run this code:
JSONParser pr = new JSONParser();
Object el = pr.parse(new InputStreamReader(new FileInputStream("moves.json")));
I get a
Exception in thread "main" java.io.FileNotFoundException: moves.json (No such file or directory)
and when I'm trying this code:
JsonReader reader = new JsonReader(new InputStreamReader(test.class.getResourceAsStream("moves.json")));
JsonElement movelist = new JsonParser().parse(reader);
I get a:
Exception in thread "main" java.lang.NullPointerException
I tried using ClassLoader and getResource and other method I searched on the web but I get the same error of null pointer exception
this is the full class:
import com.google.gson.*;
import com.google.gson.stream.JsonReader;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.*;
public class test {
public static void main(String [] args) throws IOException, ParseException {
JSONParser pr = new JSONParser();
Object el = pr.parse(new InputStreamReader(new FileInputStream("moves.json")));
JsonReader reader = new JsonReader(new InputStreamReader(test.class.getResourceAsStream("moves.json")));
JsonElement movelist = new JsonParser().parse(reader);
System.out.println("");
}
}