⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 copyfileaddlinenumber.txt

📁 java程序设计源代码
💻 TXT
字号:
01: 	import java.io.*;
02: 	public class CopyFileAddLineNumber {
03: 		public static void main (String[] args) {
04: 			String infname = "CopyFileAddLineNumber.java";
05: 			String outfname = "CopyFileAddLineNumber.txt";
06: 			if( args.length >= 1 ) infname = args[0];
07: 			if( args.length >= 2 ) outfname = args[1];
08: 	
09: 			try {
10: 				File fin = new File(infname);
11: 				File fout = new File(outfname);
12: 	
13: 				BufferedReader in = new BufferedReader(new FileReader(fin));
14: 				PrintWriter out  = new PrintWriter(new FileWriter(fout));
15: 	
16: 				int cnt = 0;	// 行号
17: 				String s = in.readLine();
18: 				while ( s != null ) {
19: 					cnt ++; 
20: 					s = deleteComments(s);						//去掉以//开始的注释
21: 					out.println(cnt + ": \t" + s );				//写出
22: 					s = in.readLine();							//读入
23: 				}			
24: 				in.close();				// 关闭缓冲读入流及文件读入流的连接.
25: 				out.close();
26: 			} catch (FileNotFoundException e1) {
27: 				System.err.println("File not found!" );
28: 			} catch (IOException e2) {
29: 				e2.printStackTrace();
30: 			}
31: 		}
32: 	
33: 		static String deleteComments( String s ) //去掉以//开始的注释
34: 		{
35: 			if( s==null ) return s;
36: 			int pos = s.indexOf( "//" );
37: 			if( pos<0 ) return s;
38: 			return s.substring( 0, pos );
39: 		}
40: 	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -