比如这篇文章 你要copy其代码 那么 就会有这个行的提示符号 也会copy出来。
package stream; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CopyFileToJavaCode { public static final String dirPath = "c:/code1.txt"; public static final String toPath = "c:/code2.txt"; private static String getCodeStr(String str){ Pattern pattern = Pattern.compile("//b[0-9]+//."); Matcher matcher = pattern.matcher(str); return matcher.replaceAll(""); } public static void main(String[] args) throws Exception { File dirFile = new File(dirPath); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(dirFile),"UTF-8")); String lineStr = null; StringBuffer sb = new StringBuffer(); while((lineStr = br.readLine()) != null){ sb.append(lineStr).append("/n"); } String codeStr = CopyFileToJavaCode.getCodeStr(sb.toString()); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(toPath), false),"UTF-8")); out.write(codeStr.toString()); out.close(); br.close(); } }