-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreatePage.java
More file actions
38 lines (36 loc) · 981 Bytes
/
Copy pathCreatePage.java
File metadata and controls
38 lines (36 loc) · 981 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
29
30
31
32
33
34
35
36
37
38
import java.io.PrintWriter;
import java.io.File;
import java.util.Scanner;
import java.io.FileNotFoundException;
public class CreatePage {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
System.out.print("Enter the name of the new file -> ");
String str = kb.nextLine();
System.out.print("Enter the name of the template file -> ");
String temp = kb.nextLine();
newFile(str, temp);
System.out.println("Successfully created new page.");
}
public static void newFile(String name, String template) {
Scanner input = null;
try {
input = new Scanner(new File(template));
} catch (FileNotFoundException e) {
e.printStackTrace();
System.exit(1);
}
PrintWriter output = null;
try {
output = new PrintWriter(new File(name));
} catch (FileNotFoundException e) {
e.printStackTrace();
System.exit(1);
}
while (input.hasNext()) {
output.println(input.nextLine());
}
input.close();
output.close();
}
}