View Javadoc

1   package au.com.loftinspace.utility;
2   
3   import java.io.BufferedReader;
4   import java.io.File;
5   import java.io.FileReader;
6   import java.io.IOException;
7   
8   /***
9    * @author Jem
10   */
11  public class FileLoader {
12  
13  	/***
14  	 * @param filename
15  	 * 		The filename of the file to be loaded
16  	 * @return
17  	 * 		The contents of the file.
18  	 * @throws IOException
19  	 *      If any IOException is thrown by the underlying java.io package.
20  	 */
21  	public static String loadTextFile(String filename) throws IOException {
22  		StringBuffer returnBuffer = new StringBuffer(1024);
23  		char[] buffer = new char[1024];
24  		File file = new File(filename);
25  		BufferedReader reader = new BufferedReader(new FileReader(filename));
26  		int charsRead = reader.read(buffer);
27  		while (charsRead != -1) {
28  			returnBuffer.append(buffer, 0, charsRead);
29  			charsRead = reader.read(buffer);
30  		}
31  		return returnBuffer.toString();
32  	}
33  }