Using Gson to load a JSON file from disk.

suggest change

This will load a JSON file from disk and convert it to the given type. FileReader uses the platform default charset. JSON is UTF-8.

public static <T> T getFile(String fileName, Class<T> type) throws IOException {
    Gson gson = new GsonBuilder()
            .create();
    FileReader json = new FileReader(fileName);
    try {
        return gson.fromJson(json, type);
    } finally {
        json.close();
    }
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents