String path = "/Users/guangyi.zgy/Desktop/scene_2khas_8kno_query_1W.csv";
List newList=new ArrayList();//打开文件
File file = newFile(path);try{
InputStream instream= newFileInputStream(file);if (instream != null)
{
InputStreamReader inputreader= newInputStreamReader(instream);
BufferedReader buffreader= newBufferedReader(inputreader);
String line;//分行读取
int j = 0;while (( line = buffreader.readLine()) != null) {
newList.add(line);
}
instream.close();
String[] newA= newString[newList.size()];for(String str : newList) {
Random random= newRandom();int a =random.nextInt(newList.size());if (newA[a] == null) {
newA[a]=str;
}else{for (int i = 0; i < newA.length; i++) {if (newA[i] == null) {
newA[i]=str;break;
}
}
}
}
String pathNew= "/Users/guangyi.zgy/Desktop/NEW_scene_2khas_8kno_query_1W.csv";
File fileNew= newFile(pathNew);
fileNew.createNewFile();
OutputStream outputStream= newFileOutputStream(fileNew);
BufferedWriter bf= new BufferedWriter(newOutputStreamWriter(outputStream));boolean firstLine = true;for(String str : newA) {if(firstLine) {
bf.write(str);
firstLine= false;continue;
}if (str != null) {
bf.write("\n" +str);
}else{
System.out.println("有空行出现");
}
}
bf.close();for(String str : newA) {int count = 0;for(String str1 : newA) {if(StringUtils.equals(str1.trim(), str.trim())) {
count++;
}
}if (count > 1) {
System.out.println("有多个相同字符");
}
}
}
}catch(java.io.FileNotFoundException e)
{
}catch(IOException e)
{
}