📄 readfilelines.java
字号:
//Copyright (c) 1998, Arthur Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.
/* Reads arg[1] lines from file args[0].
*/
import java.io.*;
public class ReadFileLines {
public static void main(String [] args) {
String line;
int totalLines; // number of lines to read from the file
int count = 0; // number of lines read so far
if (args.length != 2){
System.out.print("Pass the file name and number of lines");
System.out.println(" to read as program arguments");
System.exit(1);
}
try {
totalLines = Integer.parseInt(args[1]);
}catch(NumberFormatException e) {
totalLines = 3;
}
BufferedReader f;
try {
f = new BufferedReader(new FileReader(args[0]));
System.out.println("Opening " + args[0]);
while((line=f.readLine()) != null && count++ < totalLines)
System.out.println(line);
f.close();
}catch(IOException e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -