-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileHandling.java
More file actions
34 lines (32 loc) · 1.07 KB
/
FileHandling.java
File metadata and controls
34 lines (32 loc) · 1.07 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
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class FileHandling {
public static void createfile(String x) {
// TODO Auto-generated method stub
try {
File myObj = new File(x + ".txt");
if (myObj.createNewFile()) {
System.out.println("File created: " + myObj.getName());
} else {
System.out.println("File already exists.");
}
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
public static void writefile(String x , float hasil){
try {
BufferedWriter buffer = new BufferedWriter( new FileWriter(x+ ".txt", true));
buffer.write("Hasil Operasi adalah = " + Float.toString(hasil));
buffer.newLine();
buffer.close();
System.out.println("Successfully wrote to the file.");
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}