importjava.io.BufferedReader;
importjava.io.FileInputStream;
importjava.io.FileNotFoundException;
importjava.io.InputStreamReader;
importjava.io.PrintWriter;
publicclassTest {
/**
*@paramargs
*/
publicstaticvoidmain(String[] args) {
//TODOAuto-generated method stub
String srcPath="";//源代码文件路径
String addRowNumPath="";//加行号后的文件保存路径
String removeRowNumPath="";//去行号还原后的文件保存路径
try{
BufferedReader br=newBufferedReader(newInputStreamReader(newFileInputStream(srcPath)));
PrintWriter pw=newPrintWriter(addRowNumPath);
/**
* 加行号保存
* */
String line=null;
introw=1;//行号
while((line=br.readLine())!=null){
String newline=row+" "+line;
pw.println(newline);
row++;//行号递增
pw.flush();
}
pw.close();
br.close();
/**
* 去行号还原
* */
br=newBufferedReader(newInputStreamReader(newFileInputStream(addRowNumPath)));
pw=newPrintWriter(removeRowNumPath);
while((line=br.readLine())!=null){
String newline=line.substring(line.indexOf(" "));
pw.println(newline);
pw.flush();
}
pw.close();
br.close();
}catch(Exception e) {
//TODOAuto-generated catch block
e.printStackTrace();
}
}
}