Loading...
неділю, 28 квітня 2013 р.

Loading resources bundled to JAR

XML
URL path = FromIniFiller.class.getResource("/templates/" + fileName + ".xml");
// Do not open XML file, but pass URL as parameter to DocumentBuilder.parse
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(path.toURI().toString());
doc.getDocumentElement().normalize();

INI4J
URL path = FromIniFiller.class.getResource("/templates/" + fileName + ".ini");
// open ini from path
Ini ini = new Ini(path);

JSON via GSON

InputStream is = getClass().getResourceAsStream("/templates/" + fileName + ".json");
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String json = br.readLine();
//convert the json string back to object
JsonObject obj = gson.fromJson(json, JsonObject.class);


--
Щиро Ваш, Akceptor
http://akceptor.org

0 коментарі:

 
TOP