dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Reading a File via GSON

See an example of how to read a file via GSON.


advertisement

The following example reads a JSON file via JSON:

// create Gson instance
Gson gson = new Gson();

// create a Reader
Reader reader = Files.newBufferedReader(Paths.get("myfile.json"));

// JSON file to map
Map map = gson.fromJson(reader, Map.class);

// print map
for (Map.Entry entry : map.entrySet()) {
   System.out.println(entry.getKey() + "=" + entry.getValue());
}

// close reader
reader.close();

 

Visit the DevX Tip Bank

 



   
Thanks for your registration, follow us on our social networks to keep up-to-date