-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileIO.java
More file actions
38 lines (34 loc) · 810 Bytes
/
FileIO.java
File metadata and controls
38 lines (34 loc) · 810 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
34
35
36
37
38
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
public class FileIO {
public static void saveFile(String color, String path) {
PrintStream w = null;
try {
File f = new File(path);
w = new PrintStream(f);
w.println(color);
} catch (FileNotFoundException ex) {
} finally {
w.close();
}
}
public static String loadFile(String path) {
BufferedReader r = null;
try {
File file = new File(path);
r = new BufferedReader(new FileReader(file));
StringBuilder s = new StringBuilder();
do {
s.append(r.readLine() + ",");
} while (r.readLine() != null);
r.close();
return s.toString();
} catch (IOException ex) {
}
return null;
}
}