2013-03-13 2 views
3

유니 코드 문자 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); 
} 
+0

'\ u0002'을 사용했을 때 작동하지 않았던 것은 무엇입니까? –

+0

Simple :'if (myString.contains ("\ u0002")) System.out.println ("찾았습니다");'찾지 못했습니다. – Dimme

+0

사람들은 투표를 중지하고 실제 질문을 읽을 수 있습니까? – Dimme

답변

0

이 내가 구문 분석하고 어떻게 그것. 오류 메시지의 0x{2}은 Java에서 "\u0004"입니다. 이를 대체하면 오류 메시지가 제거됩니다.

+1

내 생각에 SAX 라이브러리에는 버그가 있고,'{2}'는 0004에 소비되었고'{1} '은 \ u0004가 들어있는 속성이 무엇이든간에. –

+1

나는 Etienne에 동의한다. 파서 작성자가 그 오류 메시지를'MessageFormat' 형식 문자열로 사용하려고했으나 그렇게하지 않았습니다. '{1}'과'{2} '는 형식 인수의 자리 표시 자입니다. – VGR

관련 문제