-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCatCommand.java
More file actions
28 lines (25 loc) · 858 Bytes
/
CatCommand.java
File metadata and controls
28 lines (25 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package IO;
import java.io.*;
public class CatCommand extends Command{
public CatCommand() {
super("cat");
}
@Override
public void action(String[] cmd) {
if (cmd.length > 1) {
File file = new File(Main.wd, cmd[1]);
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (FileNotFoundException e) {
System.out.println("File not found: " + e.getMessage());
} catch (IOException e) {
System.out.println("Error reading file: " + e.getMessage());
}
} else {
System.out.println("No file specified. Usage: cat <file>");
}
}
}