如何在java的xml文件中写入特殊字符(interpunct)? [英] how to write special characters(interpunct) in a xml file in java?
问题描述
我在 JAVA 中使用 UTF-8 编写 xml 文件时遇到问题.问题: 我有一个文件名中有一个interpunct(middot)(·)的文件.当我尝试在 xml 标签中写入文件名时,使用 java 代码我会在文件名中得到一些垃圾数字,例如 而不是·
I have a problem in writing a xml file with UTF-8 in JAVA. Problem: I have a file with filename having an interpunct(middot)(·) in it. When im trying to write the filename inside a xml tag, using java code i get some junk number like in filename instead of ·
OutputStreamWriter osw =new OutputStreamWriter(file_output_stream,"UTF8");
OutputStreamWriter osw =new OutputStreamWriter(file_output_stream,"UTF8");
上面是我用来编写xmlfile的java代码.谁能告诉我为什么要理解和解决问题?提前致谢
Above is the java code i used to write the xmlfile. Can anybody tell me why to understand and sort the problem ? thanks in advance
推荐答案
Java 源代码默认为 UTF-16.如果您的角色不在其中,请使用转义符:
Java sources are UTF-16 by default. If your character is not in it, then use an escape:
String a = "\u00b7";
或者告诉您的编译器使用 UTF-8,然后按原样将其写入代码.
Or tell your compiler to use UTF-8 and simply write it to the code as-is.
这篇关于如何在java的xml文件中写入特殊字符(interpunct)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!