我可以用任何其他方法來讀取.TXT文件中的分號分隔字符串成了地圖,而不是* sourceArra * Y從.txt讀取和存儲到的Hashmap
public static void main(String[] args) throws IOException {
try {
ArrayList<Synset> booleansynsets = null;
ArrayList<Synset> booleanduplicatesynsets = null;
Map<String, String> basebooleanentitieslist = new HashMap<String, String>();
BufferedReader bufferedReader = new BufferedReader(new FileReader("C:\\Users\\anand\\Desktop\\updatedDuplicateBooleanEntitiesList-sorted.txt"));
String line = "";
while ((line = bufferedReader.readLine()) != null) {
String[] sourceArray = line.split(";");
basebooleanentitieslist.put(sourceArray[0],sourceArray[1]);
System.out.println(line);
}
//更新一個
bufferedReader.toString();
StringTokenizer st1 = new StringTokenizer(bufferedReader.toString(),";");
while ((line = bufferedReader.readLine()) != null && st1.hasMoreTokens()) {
// String[] sourceArray = line.split(";");
basebooleanentitieslist.put(st1.nextToken(";"), st1.nextToken());
System.out.println(line);
}
什麼是(目前)這種方法的問題? – adatapost 2011-12-29 05:50:24
您的方法非常簡單直接,過度優化只會使其變得複雜。 – medopal 2011-12-29 06:10:43
目前的方法沒有問題,但感覺是否它的長度,我的意思是有沒有方法來優化它,而不使用sourceArray。 – 2011-12-29 06:10:46