我有一個程序可以讀取一個csv文件。 csv文件有兩列,一列用於簇號,另一列用於用戶。我所需要的程序不是重複用戶。相反,要向用戶寫入一次,並在每個羣集中寫入1(如果用戶已在該羣集中顯示)。如何讓用戶在閱讀csv文件時出現一次?
包解析;
public static void main(String[]args){
String fileName= "ClusterResult(final1).csv";//reading the file
File file = new File(fileName);
try {
Scanner inputStream = new Scanner(file);
while (inputStream.hasNext()){
String data = inputStream.next();
String [] myArray= data.split(",");
for(int i =0; i<=27;i++){// because I have 27 clusters
Arrays.sort(myArray);
int founditem= Arrays.binarySearch(myArray, String.valueOf(i));
if (founditem>-1)
System.out.print("1"); //if the user name showed in the cluster the user should have one next to the cluster number
else
System.out.print("0");
}
System.out.println();
System.out.println(myArray[1]);
}
inputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
程序的輸出是:
1000000000000000000000000000
ElDaddy
1000000000000000000000000000
Lxve
1000000000000000000000000000
Lxve
0000001000000000000000000000
ElDaddy
,它應該是例如:
1000001000011000010100000000
ElDaddy
不是很清楚'cluster'的東西。顯示一個輸入示例? – PeterMmm
你可以發佈csv的樣本嗎? – rpax