package com.jxufe.dormitory;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
/**
* 此类消除复制别人代码时带来的痛苦。
* 以前在网上下载一些大牛的代码时总会遇到这样的问题,代码的前面带有数字。
* 给我们阅读代码带来的极大的不便,我以前就是先把别人的代码复制下来一个一个的删除,这不仅浪费的时间,还让我们阅读代码的兴致都没有了。
* 后来我尝试用正则表达式来解决我的问题,虽有一点成效但还是有可能把代码也给删除了,特别是当我们看比较长的带码时,还是要补好多代码的。
* 用这个类你将摆脱这些问题
* @author jack_one_one
* @version 创建时间:2016年4月17日 下午10:03:46
*
*/
public class EliminateDigiterDemo {
public static void main(String[] args) throws IOException {
EliminateDigiterDemo eliminate= new EliminateDigiterDemo();
eliminate.eliminateDigiter("D:/java代码/MyCode/BlogLearning/d.txt","C:/Users/jack/Desktop/f.java"
+ "");
}
// public void eliminateDigiter(String needDealFilePath) throws IOException{
//
// File willDealfile = new File(needDealFilePath);
//
//
// FileInputStream fi =null;
// BufferedInputStream bi=null;
// try {
// fi = new FileInputStream(willDealfile);
// bi = new BufferedInputStream(fi);
// byte[] bytes = new byte[1024];
// int r ;
// while((r=bi.read(bytes))!=-1){
//
// String temp = new String(bytes);
// temp = temp.substring(temp.indexOf("."));
// System.out.println(new String(bytes));
// }
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// }finally{
// if(fi != null)
// fi.close();
// if(bi != null)
// bi.close();
// }
// }
/**
*
*@param needDealFilePath 复制下的代码存放的位置
*@param SavingPath 把代码保存到的位置
*@throws IOException
*/
public void eliminateDigiter(String needDealFilePath,String SavingPath) throws IOException{
Reader reader = null;
BufferedReader br = null;
Writer writer = null;
BufferedWriter bw= null;
try {
writer = new FileWriter(SavingPath);
// bw = new BufferedWriter(writer);
reader = new FileReader(needDealFilePath);
br = new BufferedReader(reader);
String temp="";
while(temp != null){
temp = br.readLine();
if(temp !=null &&temp.indexOf(".") != -1)
temp = temp.substring(temp.indexOf(".")+1);
if(temp != null)
writer.write(temp+"\n");
System.out.println(temp);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(reader != null)
reader.close();
if(br != null)
br.close();
if(writer != null)
writer.close();
}
}
}
消除复制别人代码的行数以及点号
最新推荐文章于 2022-11-27 13:25:14 发布