Repository navigation
Expand file tree
/
Copy pathQuiz07.java
More file actions
71 lines (61 loc) · 2.7 KB
/
Copy pathQuiz07.java
File metadata and controls
71 lines (61 loc) · 2.7 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class Quiz07 {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
File file = new File();
int menuOption;
do{
do{
System.out.println("1. Diplay the content of a file");
System.out.println("2. Merge files");
System.out.println("3. Quit");
System.out.print("Select a menu option: ");
menuOption = scanner.nextInt();
}while(menuOption < 1 || menuOption > 3);
switch(menuOption){
case 1:
System.out.print("Enter a file path: ");
String path = scanner.next();
try{
String fileString = file.loadFile(path);
System.out.print(fileString);
}
catch(FileNotFoundException ex){
System.out.println("File not found " + ex);
}
catch(IOException ex){
System.out.println("Read error " + ex);
}
catch(Exception ex){
System.out.println("Unknown error " + ex);
}
break;
case 2:
System.out.print("How many files will be merged: ");
int numberOfSources = scanner.nextInt();
String[] sources = new String[numberOfSources];
for(int i = 0; i < numberOfSources; i ++){
System.out.printf("Enter the path of source #%d: ", i + 1);
sources[i] = scanner.next();
}
System.out.print("Enter the path of the target file: ");
String target = scanner.next();
try{
file.mergeFiles(sources, target);
}
catch(FileNotFoundException ex){
System.out.println("File not found " + ex);
}
catch(IOException ex){
System.out.println("Read/Write error " + ex);
}
catch(Exception ex){
System.out.println("Unknown error " + ex);
}
break;
}
}while(menuOption != 3);
}
}