2010-05-25 192 views

回答

1

嗨Nithi确保 “远程-config.xml中” 目标id和源名称是正确的。

1

问题中没有足够的细节。

我的猜测, 看起来像你试图读取UTF-8编码的东西,它不是有效的UTF-8编码。

2

您的XML文档具有BOM标记,因为它是使用Windows程序创建的。

Java不支持开箱即用。

关于BOM: http://www.unicode.org/faq/utf_bom.html

因此,要么请确保您的XML文档没有BOM标记,(如果它是你的DS配置文件),或 使用这样的事情在你的InputStream:

(不是我的代码) http://koti.mbnet.fi/akini/java/unicodereader/UnicodeInputStream.java.txt

Usage pattern: 
String enc = "ISO-8859-1"; // or NULL to use systemdefault 
FileInputStream fis = new FileInputStream(file); 
UnicodeInputStream uin = new UnicodeInputStream(fis, enc); 
enc = uin.getEncoding(); // check and skip possible BOM bytes 
InputStreamReader in; 
if (enc == null) in = new InputStreamReader(uin); 
else in = new InputStreamReader(uin, enc); 
0
ByteArrayInputStream test = new ByteArrayInputStream(xml.trim().getBytes()); 
Document document = null; 
try { 
    document = dbf.newDocumentBuilder().parse(test); 
} catch (Exception e) { 
    System.out.println("Fehler 1" + e.getMessage()) ; 
    try { 
     test.close(); 
     // ... that works: String xml_x = FkString.replace(xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); 
     // Replace UTF-8 to UTF8 ... works 
     String xml_x = FkString.replace(xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "<?xml version=\"1.0\" encoding=\"UTF8\"?>"); 
     test = new ByteArrayInputStream(xml_x.trim().getBytes()); 
     document = dbf.newDocumentBuilder().parse(test); 
    } catch (Exception e1) { 
     System.out.println("Fehler 2" + e1.getMessage()) ; 
    } 
} 
相关问题