Created
December 31, 2019 09:28
-
-
Save victory-sokolov/3fa3cb90b6a974f442e20018b9ddc56a to your computer and use it in GitHub Desktop.
Read/Write JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.json.simple.JSONObject; | |
import org.json.simple.parser.JSONParser; | |
import org.json.simple.parser.ParseException; | |
public static JSONObject readJSON(String file) throws IOException, ParseException { | |
JSONParser parser = new JSONParser(); | |
FileReader config = new FileReader(file); | |
Object obj = parser.parse(config); | |
return (JSONObject) obj; | |
} | |
public static void writeToJSON(JSONObject jsonObject, String path) throws IOException { | |
FileWriter file = new FileWriter(path); | |
file.write(jsonObject.toJSONString()); | |
file.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment