I Want to save a xml File on Android before I asked a questions how to Get a File now I'm stuck ;( I use Gluon(Netbeans plugin and did already everything what He said: JavaFXPorts(Gluon Plugin) Saving Files on Android
Can you help me I want to save a XML File on Android, this is my Code yet:
public static void loadConfig() throws JAXBException { if (ConfigFile.length() != 0) { JAXBContext jaxbContext = JAXBContext.newInstance(Info.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); info = (Info) jaxbUnmarshaller.unmarshal(ConfigFile); } else { info = new Info(); } } public static void saveConfig() { try { info.setAge(10); JAXBContext context = JAXBContext.newInstance(Info.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(info, ConfigFile); } catch (PropertyException ex) { Logger.getLogger(STM_WU_LABOR.class.getName()).log(Level.SEVERE, null, ex); } catch (JAXBException ex) { Logger.getLogger(STM_WU_LABOR.class.getName()).log(Level.SEVERE, null, ex); } } public File getFile() throws IOException { File path = PlatformFactory.getPlatform().getPrivateStorage(); return new File(path, "config.xml"); } Here is how i call it:
ConfigFile = getFile(); if (!ConfigFile.exists()) { ConfigFile.createNewFile(); } And this is the Info class:
package com.stm_wu_labor; import javax.xml.bind.annotation.XmlRootElement; /** * * @author Merduma */ @XmlRootElement public class Info { Info() { } public Info(String gender, int age, int SchoolClass) { this.gender = gender; this.age = age; this.SchoolClass = SchoolClass; } private String gender; public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public int getSchoolClass() { return SchoolClass; } public void setSchoolClass(int SchoolClass) { this.SchoolClass = SchoolClass; } private int age; private int SchoolClass; } The Programm is for a school project
No comments:
Post a Comment