Repository navigation
Expand file tree
/
Copy pathFileHandling.java
More file actions
57 lines (48 loc) · 1.49 KB
/
Copy pathFileHandling.java
File metadata and controls
57 lines (48 loc) · 1.49 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
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Scanner;
import java.io.File;
import javax.swing.JOptionPane;
public class FileHandling {
private final String FilePath;
public FileHandling(String FilePath){
this.FilePath = FilePath;
}
public void Write(String c,boolean status){
try{
FileWriter writer = new FileWriter(new File(this.FilePath),status);
writer.write(c);
writer.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(null, "Error: Something went wrong");
}
}
public void Write(String c){
try{
FileWriter writer = new FileWriter(new File(this.FilePath));
writer.write(c);
writer.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(null, "Error: Something went wrong");
}
}
public String Read(){
String o = "";
try{
Scanner reader = new Scanner(new File(this.FilePath));
while(reader.hasNext()){
o+=reader.nextLine();
}
reader.close();
return o;
}
catch(Exception Error){
JOptionPane.showMessageDialog(null,"File not found Exception");
return "";
}
}
}