方法一 百度
方法二 百度找到我
package io.terminusxxxxxxl;
import io.terminus.common.utils.Arguments;
import java.io.*;
/**
* @author XXXXXXX
*/
public class A {
public static void A(String[] args) throws IOException {
FileReader reader = new FileReader("/Users/xxx/Desktop/11.txt");
BufferedReader reader1 = new BufferedReader(reader);
String str = reader1.readLine();
StringBuffer buffer = new StringBuffer();
String company,area,serverId;
String[] areas ;
int index1;
while(str!=null && str.trim().length()>0){
if(str.indexOf(",")>0) {
serverId = str.substring(0, str.indexOf(","));
areas = str.substring(str.indexOf(",")+1).split(",");
if(areas!=null && areas.length>1) {
company = areas[0];
for (String a:areas) {
if(a.equals(company)){
continue;
}
buffer.append("(").append(serverId).append(",\"").append(company).append("\",").append("\"").append(a).append("\"),");
}
}
}
str = reader1.readLine();
}
File file = new File("/Users/xxx/Desktop/result1.txt");
if(!file.exists()){
file.createNewFile();
}
FileWriter writer = new FileWriter(file,Boolean.FALSE);
writer.write(buffer.toString());
writer.close();
reader1.close();
}
}