findchar.java

来自「nanjing university cs 的java课件。 对新手很有用。付」· Java 代码 · 共 25 行

JAVA
25 行
字号
import java.io.*;

public class Findchar {
	public static void main(String[] args) throws Exception {
		if (args.length != 2) {
			 throw new Exception("need char / file");
		}
		int match = args[0].charAt(0);
		FileInputStream
			fileIn = new FileInputStream(args[1]);
		LineNumberInputStream
			in = new LineNumberInputStream(fileIn);
		int ch;
		while ( (ch = in.read()) != -1) {
			if (ch == match) {
				System.out.println
					("‘" + (char) ch + "’at line" +in.getLineNumber());
				System.exit(0);
			}
		}
		System.out.println(ch + "not found");
		System.exit(1);
	}
}

⌨️ 快捷键说明

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