-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileUtil.java
More file actions
62 lines (57 loc) · 1.46 KB
/
FileUtil.java
File metadata and controls
62 lines (57 loc) · 1.46 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
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class FileUtil {
public static boolean readFile(StringBuffer buffer, String fileSrc){
try {
FileReader fileReader = new FileReader(fileSrc);
BufferedReader br = new BufferedReader(fileReader);
String temp = null ;
while((temp = br.readLine())!= null) {
buffer.append(temp);
}
return true;
}catch(FileNotFoundException e) {
e.printStackTrace();
}catch(IOException e) {
e.printStackTrace();
}
return false;
}
public static boolean writeFile(String args) {
try {
File file = new File("./src/output.txt");
if(!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile(),true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(args);
bw.close();
return true;
}catch(IOException e) {
e.printStackTrace();
return true;
}
}
public static boolean clearFile() {
try {
File file = new File("./src/output.txt");
if(!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile(),true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("");
bw.close();
return true;
}catch(IOException e) {
e.printStackTrace();
return true;
}
}
}