About the functionality of FileReader
来源:互联网 发布:淘宝客群怎么拉人 编辑:程序博客网 时间:2024/05/02 01:10
The little program just to filter the row number of the beginning of every line which the code being copyed in web page:
package com.inc.bbwl;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Scanner;
public class ChangeContent {
public void changeContent(){
String filePath = null;
Scanner scanner = new Scanner(System.in);
filePath = scanner.nextLine();
FileReader fileReader = null;
BufferedReader reader = null;
FileWriter fileWriter = null;
BufferedWriter writer = null;
try {
//String s = null;
StringBuffer bufferOriginal = new StringBuffer();
fileWriter = new FileWriter(filePath.substring(0,filePath.lastIndexOf(".")) + "_New.txt");
writer = new BufferedWriter(fileWriter);
fileReader = new FileReader(filePath);
reader = new BufferedReader(fileReader);
String original = "";
String destination = "";
//Pattern pattern = Pattern.compile(regex);
StringBuffer bufferNew = new StringBuffer();
while( (original = reader.readLine())!=null){
//System.out.println(original);
destination = original.replaceFirst("^\\d+\\.", "");
//System.out.println(destination);
writer.write(destination);
writer.newLine();
writer.flush();
bufferOriginal.append(original);
bufferNew.append(destination);
}
//String regex = "(?m)(^\\d+)[.]*";
//Matcher matcher = pattern.matcher(bufferOriginal.toString());
//while(matcher.find()){
// System.out.println("group:"+matcher.group(1));
// matcher.appendReplacement(bufferNew, "");
//}
//matcher.appendTail(bufferNew);
System.out.println("==== Origial:");
System.out.println(bufferOriginal.toString());
System.out.println("==== Result: ");
System.out.println(bufferNew.toString());
} catch (Exception e){
e.printStackTrace();
} finally{
if(reader!=null){
try{
reader.close();
} catch(Exception e){
e.printStackTrace();
}
}
if(fileReader!=null){
try{
fileReader.close();
} catch(Exception e){
e.printStackTrace();
}
}
if(writer!=null){
try{
writer.close();
} catch(Exception e){
e.printStackTrace();
}
}
if(fileWriter!=null){
try{
fileWriter.close();
} catch(Exception e){
e.printStackTrace();
}
}
}
}
}
- About the functionality of FileReader
- the functionality of an "nbtstat -A" code
- The Functionality of the Future Is Here @ JDJ
- Functionality in affectation of underground substructure in the estimated
- SymPy学习之Basic functionality of the module
- About the type of backup!
- About the address of variable
- Highlights of Cygwin Functionality
- The node about the project of DJ
- About the edition of Windows Server 2003
- About The Adventures of Tom Sawyer
- About the Usage of fseek and ftell
- About the return value of SetTimer function
- More about the Operations of string
- about the statue of historical period.
- About the String Functions of XSLT
- about the two warning of sprintf()
- About the size of APK file
- 程序员必备的七大面向对象设计原则(三)
- SSH框架 不能保存 和修改,但能查询数据库记录
- vim/gvim+taglist+cscope使编程更容易
- 不可小觑的“jquery”
- 16.2.7 识别可运行程序
- About the functionality of FileReader
- VB作业
- 抓取本地网页中的email地址
- nginx的rewrite机制
- 实验,求高手帮忙做下,小弟在此谢过了啊,大侠帮忙的来啊
- shell 中调用另一个shell (fork, exec, source)
- MVC框架系统,从底层bean--dao--service--action。在各层建立common父类
- BT安全攻略笔记
- Apache MPM介绍