finished basic account add
[Bookkeeping.git] / src / com / interrupt / util / FileUtil.java
blob03915503efcf7ac0f593ea952ec16b5832219231
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;
9 import java.io.Reader;
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);
28 boolean eof = false;
29 String eachLine = null;
30 while (!eof) {
32 eachLine = buff.readLine();
33 if (eachLine == null) {
34 eof = true;
36 else {
37 sbuffer.append(eachLine);
40 return sbuffer.toString();