网页复制代码去行标
在CSDN或者ITEYE等网站上,如果直接复制代码,复制的代码中可能有多余的行标。
例如:
1.public class MyThread implements Runnable { 2. public void run() { 3. for(int i=0; i<10; i++){ 4. System.out.println(Thread.currentThread().getName()+":"+i); 5. } 6. } 7.} 8.public class MyThreadClient { 9. public static void main(String[] args){ 10. Thread t = new Thread(new MyThread()); 11. t.start(); 12. for(int i=0; i<10; i++){ 13. System.out.println(Thread.currentThread().getName()+":"+i); 14. Thread.yield(); 15. } 16. } 17.} package my.tool.file.convertor;import java.io.File;import java.io.FileFilter;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;/** * * 一个简单的文件过滤器,主要用于过滤到没有内容的空文件。 * * @author Eric * */public class EmptyFileFilter implements FileFilter {public boolean accept(File pathname) {return !isFileEmpty(pathname);}private boolean isFileEmpty(File file) {FileInputStream fis = null;boolean flag = true;try {fis = new FileInputStream(file);try {if (fis.available() != 0) {flag = false;}} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {if (null != fis) {try {fis.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {fis = null;}}}return flag;}}package my.tool.file.convertor;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;public class FileConvertor {private static final String REGEX_LINE_NUMBER = "^*\\d{1,}+\\.";public void convert(String srcFolder, String destFolder) {for (File file : new File(srcFolder).listFiles(new EmptyFileFilter())) {convertFile(file, destFolder);System.out.println(file.getName() + " is converted.");}}private void convertFile(File file, String destFolder) {BufferedReader br = null;BufferedWriter bw = null;try {br = new BufferedReader(new FileReader(file));bw = new BufferedWriter(new FileWriter(new File(destFolder, file.getName())));String line = null;while (null != (line = br.readLine())) {bw.write(removeLineNumber(line));bw.newLine();}} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {if (br != null) {try {br.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {br = null;}}if (null != bw) {try {bw.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {bw = null;}}}}private String removeLineNumber(String value) {value = value.replaceAll(REGEX_LINE_NUMBER, "");return value;}}package my.tool.file.convertor;public class Main {private static final String DESTINATION_FOLDER = "D:\\DestFolder";private static final String SOURCE_FOLDER = "D:\\SrcFolder";public static void main(String[] args) {System.out.println("Source Folder ==> " + SOURCE_FOLDER);System.out.println("Destination Folder ==> " + DESTINATION_FOLDER);System.out.println("Convert Files start.......");long start = System.currentTimeMillis();new FileConvertor().convert(SOURCE_FOLDER, DESTINATION_FOLDER);long end = System.currentTimeMillis();System.out.println("Convert Files end.......");System.out.println("Total elapsed time ==> " + (end - start)+ "ms");}}
