使用 simplexml 写入内部存储
我使用 SimpleXml 将 XML 文件写入 Android 设备的内部存储。该文件在 data/data/package_name/file_name.xml
中创建,但大小为 0 KB。这是我的代码:
Room newroom = new Room();
newroom.setRid(String.valueOf(numRoom));
newroom.setRname(roomName);
// serialize to XML using SimpleXML framework
Serializer serializer = new Persister();
File result = new File("/data/data/de.dcj.wifi/files", FILENAME);
try {
serializer.write(newroom, result);
} catch (Exception e1) {
e1.printStackTrace();
}
logcat 中没有错误。谁能指出我哪里做错了?谢谢!
I use SimpleXml to write XML file to internal storage in Android device. The file is created in data/data/package_name/file_name.xml
, but the size is 0 KB. Here is my code:
Room newroom = new Room();
newroom.setRid(String.valueOf(numRoom));
newroom.setRname(roomName);
// serialize to XML using SimpleXML framework
Serializer serializer = new Persister();
File result = new File("/data/data/de.dcj.wifi/files", FILENAME);
try {
serializer.write(newroom, result);
} catch (Exception e1) {
e1.printStackTrace();
}
There's no error in the logcat. Can anyone point out where I do wrong? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我自己已经有了答案!显然,您必须初始化要序列化的对象中的所有字段;)
Ok, I've got the answer myself! Apparently, you have to initialize all the fields in the object you want to serialize ;)