我有一個從HTML頁面提取西里爾文內容到文本文件。西里爾文在這個文件中是可以的。然後我使用這個文件來使用Jena創建一個RDF文件。這裏是我的代碼:使用jena庫將西里爾文寫入RDF文件
private void createRDFFile(String webContentFilePath) throws IOException {
// TODO Auto-generated method stub
Model model = ModelFactory.createDefaultModel();
RDFWriter writer = model.getWriter("RDF/XML");
writer.setProperty("showXmlDeclaration", "true");
writer.setProperty("showDoctypeDeclaration", "true");
writer.setProperty("tab", "8");
Writer out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(rdfFilePath), "UTF8"));
Resource resDest = null;
Property hasTimeStart = model.createProperty(ns + "#hasTimeStart");
Property distrName = model.createProperty(ns + "#distrName");
Property moneyOneDir = model.createProperty(ns + "#moneyOneDir");
Property moneyTwoDir = model.createProperty(ns + "#moneyTwoDir");
Property hasTimeStop = model.createProperty(ns + "#hasTimeStop");
BufferedReader br = new BufferedReader(new FileReader(
webContentFilePath));
String line = "";
while ((line = br.readLine()) != null) {
String[] arrayLine = line.split("\\|");
resDest = model.createResource(ns + arrayLine[5]);
resDest.addProperty(hasTimeStart, arrayLine[0]);
resDest.addProperty(distrName, arrayLine[1]);
resDest.addProperty(moneyOneDir, arrayLine[2]);
resDest.addProperty(moneyTwoDir, arrayLine[3]);
resDest.addProperty(hasTimeStop, arrayLine[4]);
}
br.close();
model.write(System.out, "RDF/XML");
writer.write(model, out, null);
}
當我打開RDF文件西里爾就像РўРРђРќРЎРљРћРџ-Р'РРўРћР>Рђ? 有人可以幫我嗎?
我錯了。首先我忘記了OutputStreamWriter中的utf-8編碼設置,然後我沒有在我打開的文本編輯器中重新加載文件。現在在文本編輯器中是OK的,但在Eclipse中我仍然收到這些奇怪的字符。 – vikifor
所以你的文件是可以的,除非你在Eclipse中打開它?您應該將Eclipse的默認編碼設置爲UTF-8,請參閱http://www.eclipse.org/forums/index.php/t/29511/以獲得一些建議或其他類似主題的StackOverflow問題。 –