-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCat.java
More file actions
38 lines (30 loc) · 1.15 KB
/
Cat.java
File metadata and controls
38 lines (30 loc) · 1.15 KB
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
29
30
31
32
33
34
35
36
37
38
package src;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Cat {
public static void main(String[] args) {
Scanner inputScanner = new Scanner(System.in);
while (true) {
System.out.print("파일 이름을 입력하세요 (예: 'catExample', 종료하려면 'exit'): ");
String fileName = inputScanner.nextLine();
if (fileName.equalsIgnoreCase("exit")) {
System.out.println("프로그램을 종료합니다.");
break;
}
File file = new File(fileName);
if (!file.exists()) {
System.out.println("파일이 존재하지 않습니다: " + fileName);
continue;
}
try (Scanner fileScanner = new Scanner(file)) {
while (fileScanner.hasNextLine()) {
System.out.println(fileScanner.nextLine());
}
} catch (FileNotFoundException e) {
System.out.println("파일을 읽을 수 없습니다: " + fileName);
}
}
//inputScanner.close();
}
}