Using Gson to load a JSON file from disk.
suggest changeThis 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();
}
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents