我正在寻求帮助。我有一个应用程序在工作中生成一个带有用户信息的csv。我想使用Java并获取数据,删除重复信息,重新排列信息并创建电子表格,以使生活更轻松。 csv按以下格式生成,但要大得多:
21458952, a1234, Doe, John, technology, support staff, work phone, 555-555-5555
21458952, a1234, Doe, John, technology, support staff, work email, johndoe@whatever.net
21458952, a1234, Doe, John, technology, support staff, work pager, 555-555-5555
99946133, b9854, Paul, Jane, technology, administration, work phone, 444-444-4444
99946133, b9854, Paul, Jane, technology, administration, work email, janepaul@whatever.net
99946133, b9854, Paul, Jane, technology, administration, work pager, 444-444-4444
99946133, b9854, Paul, Jane, technology, administration, cell phone, 444-444-4444
我想删除重复项并将数据排列在适当的列中。
ID | PIN | Lname | Fname | Dept | team | work px | work email
我一直在尝试使用BufferedReader构建数组来存储数据,但是我遇到了处理重复数据并将数据操作到表中的困难。
这是我到目前为止的代码
public class Sort {
public static void main(String[] args) {
BufferedReader br = null;
try{
String line="";
String csvSplitBy=(",");
String outPut;
br = new BufferedReader(new FileReader("C:/Users/Jason/Desktop/test.txt")); //location where the file is retreived
while ((line = br.readLine()) !=null){ //checks to see if the data is there
String[] id = line.split(csvSplitBy);
outPut = id[0] + "," + id[1] + "," + id[2] + "," + id[3] + "," + id[4] + "," + id[5] + "," + id[6] + "," + id[7]
+ "," + id[8] + "," + id[9];//incomplete...using for test...
System.out.println(outPut); //displays the contents of the .txt file
} //ends while statement
} //ends try
catch (IOException e){
System.out.println ("File not found!");
} //ends catch
finally{
try{
if (br !=null)br.close();}
catch(IOException ex){
ex.printStackTrace();
} //ends try
} //ends finally
} //ends main method
} //结束课程排序
感谢您的帮助!
答案 0 :(得分:0)
你应该创建一个类来保存数据,然后创建一个List,然后如果数据不在列表中,添加它!