我的第一个意图是使用TransformerFactory为Android创建XML文件,我有这些错误:
W /:无法打开' /system/framework/WfdCommon.jar':没有这样的文件或目录
W / art:无法打开zip存档' /system/framework/WfdCommon.jar':I / O错误
我正在使用这个课程:
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
public class CreateXMLFile {
public static void save(String fName) {
try {
DocumentBuilderFactory dbFactory =
DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder =
dbFactory.newDocumentBuilder();
Document document = dBuilder.newDocument();
// adding root element to document
Element rootElement = document.createElement("rootelement");
document.appendChild(rootElement);
// write the content into xml file
TransformerFactory transformerFactory =
TransformerFactory.newInstance();
Transformer transformer =
transformerFactory.newTransformer();
DOMSource source = new DOMSource(document);
File file = new File(fName);
// Output to file
StreamResult result = new StreamResult(file);
transformer.transform(source, result);
// Output to console for testing:
// StreamResult consoleResult = new StreamResult(System.out);
// transformer.transform(source, consoleResult);
} catch (Exception e) {
e.printStackTrace();
}
}
}
我这样调用 .save 方法:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
.......
CreateXMLFile.save("test.xml");
}
....
}
对consol的测试运行良好,但是当我尝试将内容写入文件时,它会抛出Exeption。 我试图获取有关 WfdCommon.jar 的信息,但找不到任何信息。我不知道在哪里挖。有人可以帮帮我吗?