1 package com
.interrupt
.util
;
3 import java
.io
.BufferedReader
;
4 import java
.io
.FileNotFoundException
;
5 import java
.io
.FileReader
;
6 import java
.io
.IOException
;
7 import java
.io
.InputStream
;
8 import java
.io
.InputStreamReader
;
11 public class FileUtil
{
13 public static String
readTextFile(String fileName
) throws FileNotFoundException
, IOException
{
15 FileReader myFile
= new FileReader( fileName
);
16 return FileUtil
._readTextFile(myFile
);
18 public static String
readTextFileAsStream(String fileName
) throws FileNotFoundException
, IOException
{
20 InputStream istream
= FileUtil
.class.getResourceAsStream(fileName
);
21 InputStreamReader isreader
= new InputStreamReader(istream
);
22 return FileUtil
._readTextFile(isreader
);
24 private static String
_readTextFile(Reader fileReader
) throws FileNotFoundException
, IOException
{
26 StringBuffer sbuffer
= new StringBuffer();
27 BufferedReader buff
= new BufferedReader(fileReader
);
29 String eachLine
= null;
32 eachLine
= buff
.readLine();
33 if (eachLine
== null) {
37 sbuffer
.append(eachLine
);
40 return sbuffer
.toString();