You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB
Java

package sh.adb.sensorCommunityAPI;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class dataStore {
public boolean storeJson(String path, JSONObject json) throws IOException {
boolean check = false;
FileWriter file = new FileWriter(path);
try {
file.write(json.toJSONString());
check = true;
}catch (IOException e){
System.out.println("Can not write in file: " + path);
e.printStackTrace();
}
return check;
}
public JSONObject getjson(String path) throws IOException, ParseException {
JSONParser parser = new JSONParser();
JSONObject jsonObject = null;
try {
Object obj = parser.parse(new FileReader(path));
jsonObject = (JSONObject) obj;
} catch (Exception e) {
System.out.println("Can not create Jsonobjekt from path: " + path);
e.printStackTrace();
}
return jsonObject;
}
}