package com.lzz.test;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class DeleteFile {
/**
* 删除百度上copy的多余的前缀内容(0-10000)的数字
* @param args
*/
public static void main(String[] args) {
//原文件
File oldFile = new File("d:/old.txt");
//新文件
File newFile = new File("d:/new.txt");
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader(oldFile));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(newFile));
String oldLine = null;
String newLine = null;
while((oldLine = bufferedReader.readLine())!= null){
//读取每一行的长度
int length = oldLine.length();
if(length == 0 ){//该行为空时直接替换
newLine = oldLine;
}else if(length >0 && length<5 ){//该行只有数字
newLine = oldLine.substring(length);
}else{//截取内容
newLine = oldLine.substring(4);
}
bufferedWriter.write(newLine);
bufferedWriter.newLine();
bufferedWriter.flush();
}
} catch (IOException e) {
e.printStackTrace();
} finally{
System.out.println("执行完了");
}
}
}