main.java
来自「java的经典例子」· Java 代码 · 共 30 行
JAVA
30 行
import java.io.*;
class Main {
public static void main(String[] args) {
if (args.length != 2) {
System.err.println("usage: java Main <inputfile> num");
}
int num = Integer.parseInt(args[1]); // number of lines
try {
BufferedReader in =
new BufferedReader(new FileReader(new File(args[0])));
PrintWriter out = new PrintWriter(System.out);
String str;
while (num > 0 && (str = in.readLine()) != null) {
out.println(str);
--num;
}
out.flush();
out.close();
in.close();
} catch (NumberFormatException e) {
System.err.println(e);
} catch (FileNotFoundException e) {
System.err.println(e);
} catch (IOException e) {
System.err.println(e);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?