유니 코드 문자 0x{2}
을 Java로 작성하려면 어떻게해야합니까?Java에서 유니 코드 0x2 쓰기
"\u0002"
으로 시도했지만 작동하지 않는 것 같습니다.
내가이 문자를 찾아야하는 이유는 구문 분석 할 수 있기 전에 XML 파일에서이를 대체해야하기 때문입니다.
구문 분석 중에 오류 : 을 입력하고 \u0002
을 바꾸어도 오류가 해결되지 않습니다.
try {
// Fixing any invalid characters in the XML file
fixXMLFile(xmlFile);
// Get a factory
SAXParserFactory spf = SAXParserFactory.newInstance();
// Get a new instance of parser
SAXParser sp = spf.newSAXParser();
// Parse the file and also register this class for call backs
sp.parse(xmlFile, this);
} catch(Exception e) {
System.out.println(e.getLocalizedMessage());
}
그리고 수정 방법 : 그 문자가,이 타이밍에서 Wikipediate를 XML 볼 수있다 허용되지 않습니다
private void fixXMLFile(File xmlFile) throws IOException {
File tempFile = File.createTempFile("dont_delete", ".tmp");
FileWriter fw = new FileWriter(tempFile);
Reader fr = new FileReader(xmlFile);
BufferedReader br = new BufferedReader(fr);
int sdds = 0;
while(br.ready()) {
String tmp = br.readLine();
if (tmp.contains("\u0002")) System.out.println(++sdds);
fw.write(tmp.replaceAll("\u0002", "") + "\n");
}
fw.close();
br.close();
fr.close();
// Finally replace the original file.
tempFile.renameTo(xmlFile);
}
'\ u0002'을 사용했을 때 작동하지 않았던 것은 무엇입니까? –
Simple :'if (myString.contains ("\ u0002")) System.out.println ("찾았습니다");'찾지 못했습니다. – Dimme
사람들은 투표를 중지하고 실제 질문을 읽을 수 있습니까? – Dimme