消除复制别人代码的行数以及点号

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();
			
		}
		
	}
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值