try { FileInputStream file = new FileInputStream("file.txt"); int data = file.read(); while(data != -1) { System.out.print((char) data); data = file.read(); } file.close(); } catch (IOException ex) { System.out.println("Error reading file: " + ex.getMessage()); }
try { JSONObject object = new JSONObject("{ \"name\": \"John\", \"age\": 30 }"); System.out.println(object.getString("name")); System.out.println(object.getInt("age")); System.out.println(object.getBoolean("married")); // throws JSONException } catch (JSONException ex) { System.out.println("Error parsing JSON: " + ex.getMessage()); }Package/library: org.json