public static void main(String[] args) throws Exception{
String inFile = "D:\\in.txt";
String outFile = "D:\\out.txt";
BufferedReader bs = null;
BufferedWriter bw = null;
try{
bs = new BufferedReader(new FileReader(new File(inFile)));
List outData = new ArrayList();
String line = null;
String[] data = null;
//如果确定ID1一直是整数的活,可以用整数比,否则可以用字符串的equals比较
int oldId1 = 0;
int newId1 = 0;
int oldId2 = -1;
int newId2 = -1;
while((line = bs.readLine()) != null){
data = line.split(" ");
newId1 = Integer.parseInt(data[0]);
newId2 = Integer.parseInt(data[1]);
if((oldId1 != newId1) || (oldId2 != newId2)){
if(!outData.isEmpty()){
outData.add("END");
}
outData.add("START");
}
oldId1 = newId1;
oldId2 = newId2;
outData.add(data[2]);
}
if(!outData.isEmpty()){
outData.add("END");
bw = new BufferedWriter(new FileWriter(new File(outFile)));
for(String s : outData){
bw.write(s + "\r\n");
}
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(bs != null){
bs.close();
}
if(bw != null){
bw.close();
}
}
}
写了一个main方法,你自己改成带参数的方法吧!~~~
随便写的没多想,别闲不好。