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

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 ...

    UE(官方下载)

    You can use these functions to insert a file into the current file, delete the active file, send the file through email, or insert a string into the file at every specified increment HTML preview ...

    The host data copied from the machine

    The host data copied from the machine The host data copied from the machine The host data copied from the machine

    OLE Programmer's Reference

    No part of this online help system may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or information and retrieval systems, for ...

    File Splitter enables you to split large files into files of

    File Splitter enables you to split large files into files of the size that can be copied to floppy disks for transport to another machine and rejoined.

    Microsoft Codeview and Utilities User's Guide

    13.3.14 Including Line Numbers in the Map File (/LI) 13.3.15 Listing Public Symbols (/M) 13.3.16 Ignoring Default Libraries (/NOD) 13.3.17 Ignoring Extended Dictionary (/NOE) 13.3.18 Disabling Far-...

    cp-file:复制文件

    cp文件复制文件强调通过使用异步版本中的... log ( 'File copied' ) ;} ) ( ) ;原料药cpFile(源,目标,选项?) 返回一个Promise ,该Promise在复制文件时解决。cpFile.sync(源,目标,选项?)来源类型: string 您

    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. ...

    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 ...

    ebt_limit.rar_limit

    Mostly copied netfilter s ipt_limit.c, see that file for more explanation.

    2009 达内Unix学习笔记

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

    C 语言编缉神经网络工具

    In the run file, you specify a number of things. Look at demo.run in detail to see what they are; there is explanation following the run data for the two runs that tell what goes where. First, ...

    Microsoft CDIMAGE v2.52

    4 report each file name copied to image -y test option followed by number (e.g. -y1), used to generate non-standard variations of ISO-9660 for testing purposes: 1 encode trailing version number ';...

    曲线拟合工具CurveExpert 1.0

    + A plot that was copied to the clipboard failed to "clip" data points that were outside of the graphing pane, resulting in points being drawn outside of the intended area. Fixed. + The ...

    CDIMAGE 2.52

    4 report each file name copied to image -y test option followed by number (e.g. -y1), used to generate non-standard variations of ISO-9660 for testing purposes: 1 encode trailing version number ';...

    51CTO下载-DSSM335V4.part1

    If you copied the demo package directory, make sure the DSSM_335_V4_pkg.jar, jhall.jar, and the JRE directory were all copied. After the Demo has started, the user may wish to interact with the ...

    Android代码-jmdsp

    You'd also need some midi files to be copied to your file system. If you try it on a sim, do this: android-sdk-XXX/tools/adb push yoursongfile.mid /sdcard Running the app: - Tap "Load" text to open an...

    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 ...

    Win32help.zip

    No part of this online help system may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or information and retrieval systems, for ...

Global site tag (gtag.js) - Google Analytics