-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathFileUtil.java
More file actions
48 lines (43 loc) · 1.02 KB
/
FileUtil.java
File metadata and controls
48 lines (43 loc) · 1.02 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
package net.sf.j2s.core.compiler;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class FileUtil {
public static String readSource(File f) {
StringBuffer sb = new StringBuffer();
FileReader reader = null;
try {
reader = new FileReader(f);
char[] buf = new char[1024];
int read = reader.read(buf);
while (read != -1) {
sb.append(buf, 0, read);
read = reader.read(buf);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
close(reader);
}
return sb.toString();
}
/**
* Close the given FileReader.
*
* <p>In case of an error the exception and its backtrace is written to the standard error stream.
*
* @param fileReader null or the FileReader to close
*/
public static void close(FileReader fileReader) {
if (fileReader != null) {
try {
fileReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}