I have some problems by opening/ loading a generated xml-file because it's not well formed ("Invalid byte 1 of 1-byte UTF-8 sequence"). I already searched for some solutions and changed my code for getting the design as following:
System.out.println("Which Design-File shall be modified? Please enter: [file].xml");
String file = "file.xml";
// generate JDOM Document
SAXBuilder builder = new SAXBuilder();
try {
// getting rid of the UTF8 problem when reading the modified xml file
InputStream inputStream= new FileInputStream(file)
Reader reader = new InputStreamReader(inputStream,"UTF-8");
InputSource is = new InputSource(reader);
is.setEncoding("UTF-8");
Document doc = builder.build(is);
}
catch (JDOMException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
after changing the design, I write it with the XMLOutputter as followed:
String fileNew = "file_modified.xml";
FileWriter writer;
try {
Format format = Format.getPrettyFormat();
format.setEncoding("UTF-8");
writer = new FileWriter(fileNew);
XMLOutputter outputter = new XMLOutputter(format);
outputter.output(doc, writer);
} catch (IOException e) {
e.printStackTrace();
}
Does somebody has a solution for my problem? I really thought that these codelines would be solve my problem, but when I load it into the firefox it still says that it's not well formed :/.
No comments:
Post a Comment