This repository was archived by the owner on May 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathFileUtil.java
More file actions
53 lines (45 loc) · 1.33 KB
/
FileUtil.java
File metadata and controls
53 lines (45 loc) · 1.33 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
package com.code;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* Created by Administrator on 13-8-19.
*/
public class FileUtil {
public static boolean writeJsonFile(String file_name, String json_content) {
FileOutputStream fout = null;
try {
fout = new FileOutputStream(file_name);
byte[] bytes = json_content.getBytes();
fout.write(bytes);
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
if (fout != null) {
try {
fout.flush();
fout.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return true;
}
public static String readJsonFile(String file_name) {
String json_content = "";
try {
FileInputStream fin = new FileInputStream(file_name);
int length = fin.available();
byte[] buffer = new byte[length];
fin.read(buffer);
json_content = new String(buffer, "UTF-8");
fin.close();
} catch (Exception e) {
e.printStackTrace();
return json_content;
}
return json_content;
}
}