Encoding of XML files generated during Java execl operations

Source: Internet
Author: User

Java action execl is complex. For example, if you need a sophisticated format and multiple sheet tables, there is no perfect solution. Save the execl file as XML, then it is a good solution to operate execl like a text file!

However, during the specific operation, the file content saved after being edited in Java is exactly the same as that saved in execl, but it cannot be opened by execl, execl transfer to the XML in eclipse to view the UTF-8 format, Java generated XML file opened with a common text editor without garbled, but in eclipse garbled phenomenon, it should be the encoding of XML files generated by Java!

At first, filewriter could not control the format of the saved file. Instead, it used outputstreamwriter to solve the problem.

Configuration config = FreeMarkerUtil.getConfiguration(TestSaveAs.class, "template");Template template = config.getTemplate("test.xml");File file = new File("c:\\test.xml");Map root = new HashMap();Writer writer = new FileWriter(file);template.process(root, writer);writer.flush();writer.close();

 

Final code:

 

Configuration config = FreeMarkerUtil.getConfiguration(TestSaveAs.class, "template");Template template = config.getTemplate("test.xml");File file = new File("c:\\test.xml");Map root = new HashMap();Writer writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); template.process(root, writer);writer.flush();writer.close();

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.