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

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

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

    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.

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

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

    如何在C#中以高效的方式使用File.Copy()复制文件?

    File.Copy(fileName, fileName + "_copied", true); }); ``` 3. **缓冲区大小调整**:在使用FileStream时,可以通过调整缓冲区大小来优化性能。较大的缓冲区可以减少磁盘I/O次数,但会增加内存使用。 4. **文件...

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

    C# 对文件的创建,移动,复制,删除操作

    删除文件的操作由`File.Delete`方法完成。一旦调用,文件会被立即删除,除非文件被其他进程占用。例如: ```csharp string filePathToDelete = @"C:\Temp\UnwantedFile.txt"; if (File.Exists(filePathToDelete)) { ...

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

Global site tag (gtag.js) - Google Analytics