0
我必須寫一個小的Java類,它必須檢查一個xml文件的重複條目。如何使用java檢查重複條目的XML文件?
XML文件具有德文單詞和英文翻譯的鍵值。大概有20,000行。
例子:
<properties>
<entry key="Auto">car</entry>
<entry key="Bus">bus</entry>
<entry key="Auto">car</entry>
<entry key="Haus">House</entry>
</properties>
我如何讀/導入文件,之後測試他們多次入境。我的代碼查找所有元素,但沒有按照正確的順序。
這是我的代碼來讀取文件。
package translation;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Enumeration;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;
public class doubleTest {
public static void main(String[] args)
{
try {
File file = new File("C://GER_EN.xml");
FileInputStream fileInput = new FileInputStream(file);
Properties properties = new Properties();
properties.loadFromXML(fileInput);
Enumeration enuKeys = properties.keys();
while(enuKeys.hasMoreElements()) {
String key = (String) enuKeys.nextElement();
String value = properties.getProperty(key);
System.out.println(key); //+ ": " + value
}
fileInput.close();
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (InvalidPropertiesFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
這是我上面的XML示例輸出。
Auto: car
Bus: bus
Haus: house
感謝很多提前:)
請分享你的輸出 –
你的意思是找到重複鍵? –
你是什麼意思「但不是以正確的順序」? –