문제

How would I go about reading XML from a file on the device? Can you add the XML to a .res file? I know the XML parser expects a reader, but can you use a reader to read out the .res file?

Regards,

Dylan

도움이 되었습니까?

해결책

Yes, you absolutely can. Open the theme.res file with the Codename One Designer and add your xml file from the Data section on the left. Now you can load the file using the theme object as follows:

InputStream is = theme.getData("yourFile.xml");

Alternatively, You can put your xml in the class path (e.g. java source directory) and load it as follows:

InputStream is = Display.getInstance().getResourceAsStream(null, "/yourFile.xml");

Once you got an InputStream, simply wrap it with a Reader

XMLParser xmlParser = new XMLParser();
xmlParser.parse(new InputStreamReader(is, "UTF-8"));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top