forked from kalaskarpranav/Java-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_File.java
More file actions
33 lines (32 loc) · 886 Bytes
/
create_File.java
File metadata and controls
33 lines (32 loc) · 886 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
import java.io.File;
class Main {
public static void main(String[] args) {
File file = new File("JavaFile.java");
try {
boolean value = file.createNewFile();
if (value) {
System.out.println("New Java File is created.");
}
else {
System.out.println("The file already exists.");
}
}
catch(Exception e) {
e.getStackTrace();
}
String program = "class JavaFile { " +
"public static void main(String[] args) { " +
"System.out.println(\"This is file\");"+
"}"+
"}";
try {
FileWriter output = new FileWriter("JavaFile.java");
output.write(program);
System.out.println("Data is written to the file.");
output.close();
}
catch (Exception e) {
e.getStackTrace();
}
}
}