File tree Expand file tree Collapse file tree
sources/net.sf.j2s.core/src/net/sf/j2s/core/compiler Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,8 +9,9 @@ public class FileUtil {
99
1010 public static String readSource (File f ) {
1111 StringBuffer sb = new StringBuffer ();
12+ FileReader reader = null ;
1213 try {
13- FileReader reader = new FileReader (f );
14+ reader = new FileReader (f );
1415 char [] buf = new char [1024 ];
1516 int read = reader .read (buf );
1617 while (read != -1 ) {
@@ -21,8 +22,27 @@ public static String readSource(File f) {
2122 e .printStackTrace ();
2223 } catch (IOException e ) {
2324 e .printStackTrace ();
25+ } finally {
26+ close (reader );
2427 }
2528 return sb .toString ();
2629 }
30+
31+ /**
32+ * Close the given FileReader.
33+ *
34+ * <p>In case of an error the exception and its backtrace is written to the standard error stream.
35+ *
36+ * @param fileReader null or the FileReader to close
37+ */
38+ public static void close (FileReader fileReader ) {
39+ if (fileReader != null ) {
40+ try {
41+ fileReader .close ();
42+ } catch (IOException e ) {
43+ e .printStackTrace ();
44+ }
45+ }
46+ }
2747}
2848
You can’t perform that action at this time.
0 commit comments