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.
35 lines
1.1 KiB
Java
35 lines
1.1 KiB
Java
package sh.adb.sensorCommunityAPI;
|
|
|
|
import org.json.simple.JSONObject;
|
|
import org.json.simple.parser.JSONParser;
|
|
|
|
import java.io.FileReader;
|
|
import java.io.FileWriter;
|
|
import java.io.IOException;
|
|
|
|
public class DataStore {
|
|
public boolean storeJSON(String path, JSONObject json) throws IOException {
|
|
FileWriter fw = new FileWriter(path);
|
|
try {
|
|
System.out.println("store data to: " + path + " => ");
|
|
System.out.println(json.toString());
|
|
fw.write(json.toString());
|
|
fw.close();
|
|
return true;
|
|
}catch (IOException e){
|
|
System.out.println("error while soring data to: " + path);
|
|
}
|
|
return false;
|
|
}
|
|
public JSONObject readJSON(String path){
|
|
JSONParser parser = new JSONParser();
|
|
|
|
try {
|
|
System.out.println("reading file: " + path);
|
|
return (JSONObject) parser.parse(new FileReader(path));
|
|
} catch (Exception e) {
|
|
System.out.println("error while reading file: " + path);
|
|
}
|
|
return null;
|
|
}
|
|
} |