`
yjjssixa
  • 浏览: 4988 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

DELETE COPIED FILE'S LINE NUMBER

 
阅读更多
论坛里面的代码需要拿来使用的时候发现很多行号,很不方便。
试着写了很简单的程序进行处理,主要应用到JAVA 的输入输出流。

以下是所有源码:


package test.deleteNum;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
* 写一个公用的方法,用来去除复制过来代码前面的数字和点点。
*
* @author QHB1205370
*
*/
public class DeleteNumUtil {

/**
*
* @param file
*            需要处理的文件。
* @throws IOException
*/
public static void updateFile(String inputfile, String outputfile)
throws IOException {

InputStream in = new FileInputStream(inputfile);
InputStreamReader isr = new InputStreamReader(in, "GBK");
BufferedReader reader = new BufferedReader(isr);

FileWriter writer = new FileWriter(outputfile);
BufferedWriter br = new BufferedWriter(writer);

String str = null;
while ((str = reader.readLine()) != null) {
str = getNewLine(str);
br.write(str);
br.newLine();
br.flush();
}
reader.close();
br.close();
writer.close();

}

/**
* 修改每行的数据文件,把每行前面的行号去掉。
*
* @param str
* @return
*/
public static String getNewLine(String str) {
String newLine = null;
newLine = str.substring(str.indexOf(".") + 1);
return newLine;
}

// test
public static void main(String[] args) throws IOException {

String inputfile = "e:\\test.txt";
String outputfile = "e:\\another.txt";
updateFile(inputfile, outputfile);
System.out.println("文件已经重新生成。");
}

}
分享到:
评论

相关推荐

    VB编程资源大全(英文源码 文件)

    <END><br>35 , shortcut.zip How to create a shortcut to another file<END><br>36 , CountLines.zip How to count the number of lines in a text file<END><br>37 , f_165.zip How to create a ...

    Turbo C 2.00[DISK]

    .DOC file on the COMMAND LINE/UTILITIES disk also answers many common Technical Support questions. TABLE OF CONTENTS ----------------- 1. How to Get Help 2. Installation 3. Important Notes 4. ...

    2021-2022计算机二级等级考试试题及答案No.17518.docx

    8. In Java, the `package` statement should be the first line in a source file, organizing classes and interfaces into a hierarchical structure. 9. The Image control in web development is used to ...

    Turbo C 2.01[DISK]

    command-line option, as described in the file THELP.DOC. o Because of the limited memory available in the Tiny model, it no longer supports graphics functions. o The Version 1.5 graphics drivers...

    OutlookAttachView v2.73

    copied filename while copying the attachments. It also allows you to stop the copying process by clicking the stop menu. * Version 1.66 o In the 'Copy Selected Files To...' window, you can now ...

    2009 达内Unix学习笔记

    集合了 所有的 Unix命令... ln -s file1 file1.sln 创建软链接。可跨系统操作,冲破操作权限;也是快捷方式。 八、时间显示 date 显示时间,精确到秒 用法 date [-u] mmddHHMM[[cc]yy][.SS] date [-u] [+format] ...

    apktool documentation

    It will assume its up to date, so delete the file during Apktool upgrades Managing framework files Frameworks are stored in $HOME/apktool/framework for Windows and Unix systems. Mac OS X has a ...

    Senfore_DragDrop_v4.1

    doesn't extract the files and the files thus can't be copied/moved. This is caused by a quirk in WinZip; Apparently WinZip doesn't like IDataObject.GetData to be called before IDropTarget.Drop is ...

    一个跨平台的CString源码

    // 2001-APR-27 - StreamLoad was calculating the number of BYTES in one // case, not characters. Thanks to Pablo Presedo for this. // // 2001-FEB-23 - Replace() had a bug which caused infinite ...

Global site tag (gtag.js) - Google Analytics