我有一个输入文件如下:
conf/iastedCSN/KangHPLNL06 Quoc V. Phung
conf/iastedCSN/KangHPLNL06 Kungmeng Lo
conf/iastedCSN/KangHPLNL06 Hoang Nam Nguyen
conf/iastedCSN/KangHPLNL06 M. M. Lee
series/sci/ZighedAB13 Djamel Abdelkader Zighed
series/sci/ZighedAB13 Rafik Abdesselam
series/sci/ZighedAB13 Ahmed Bounekkar
series/sci/LermanG13 Isra챘l-C챕sar Lerman
我想用分隔符输出如下:
conf/iastedCSN/KangHPLNL06 | QuocV.Phung
conf/iastedCSN/KangHPLNL06 | KungmengLo
conf/iastedCSN/KangHPLNL06 | HoangNamNguyen
conf/iastedCSN/KangHPLNL06 | M.M.Lee
series/sci/ZighedAB13 | DjamelAbdelkaderZighed
series/sci/ZighedAB13 | RafikAbdesselam
series/sci/ZighedAB13 | AhmedBounekkar
series/sci/LermanG13 | Isra챘l-C챕sarLerman
但是现在,我在结果中有很多行重复,我似乎无法找出原因。我得到的输出如下:
conf/iastedCSN/KangHPLNL06 | QuocV.Phung
conf/iastedCSN/KangHPLNL06 | KungmengLo
conf/iastedCSN/KangHPLNL06 | HoangNamNguyen
conf/iastedCSN/KangHPLNL06 | M.M.Lee
conf/iastedCSN/KangHPLNL06 | M.M.Lee
series/sci/ZighedAB13 | DjamelAbdelkaderZighed
conf/iastedCSN/KangHPLNL06 | M.M.Lee
series/sci/ZighedAB13 | RafikAbdesselam
conf/iastedCSN/KangHPLNL06 | M.M.Lee
series/sci/ZighedAB13 | AhmedBounekkar
conf/iastedCSN/KangHPLNL06 | M.M.Lee
series/sci/LermanG13 | Isra챘l-C챕sarLerman
series/sci/ZighedAB13 | AhmedBounekkar
下面是源代码:
package authorgraph;
import java.io.*;
import java.util.*;
public class graph {
private static BufferedReader br;
public static void main(String[] args)
{
try{
br = new BufferedReader (new FileReader ("inproceedings-author-test1.txt"));
Map<String, String> items = new TreeMap<String, String>();
String line;
while (null != (line = br.readLine()))
{
String[] line_parts = line.split(" ");
if (line_parts.length > 1)
{
StringBuilder name = new StringBuilder(line_parts[1]);
for (int i = 2; i < line_parts.length; i++)
{
name.append(line_parts[i]);
}
items.put(new String(line_parts[0]), name.toString());
}
for (String conf: items.keySet())
{
System.out.println(conf + " | " + items.get(conf));
}
}
}
catch (IOException e) {
e.printStackTrace();
}
}
};
任何帮助将非常感激