FileOutputStream不创建xml文档

时间:2016-06-16 12:29:34

标签: android xml fileoutputstream

您好我正在尝试为xml文件编写创建/更新但是当我尝试这样做时没有任何反应。我得到E / Surface:getSlotFromBufferLocked:未知缓冲区:0xb4097390但如果相关则不要。

我的代码:

 String XMLyPerson = "";
        try {
             XMLyPerson =  createXMLPerson(entries);
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            FileOutputStream fos = openFileOutput("exml.xml", Context.MODE_PRIVATE);
            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fos);
            outputStreamWriter.write(XMLyPerson);
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

xml方法

public  static String createXMLPerson(List<Entry> list) throws IllegalArgumentException, IllegalStateException, IOException
    {

        XmlSerializer xmlSerializer = Xml.newSerializer();
        StringWriter stringWriter = new StringWriter();
        xmlSerializer.setOutput(stringWriter);

        xmlSerializer.startDocument("UTF-8", true);
        xmlSerializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);

        xmlSerializer.startTag(ns, "entries");
        for (Entry entry: list) {

            xmlSerializer.startTag(ns, "entry");

            xmlSerializer.startTag(ns, "title");
            xmlSerializer.text(entry.getTitle());
            xmlSerializer.endTag(ns, "title"); 
       for (Person p : entry.getVeiwers()) {

                xmlSerializer.startTag(ns, "reader");
                xmlSerializer.text(p.getName());
                xmlSerializer.endTag(ns, "reader");

            }
            xmlSerializer.endTag(ns, "entry");
        }
        xmlSerializer.endTag(ns,"entries");
        xmlSerializer.endDocument();
        return stringWriter.toString();
    }

1 个答案:

答案 0 :(得分:0)

您是否在android.manifest中添加了文件写入权限?

Android persmissions

WRITE_EXTERNAL_STORAGE