Read File to String with Java

On March 29, 2013, in Java, Programming, by LuCuS

Read file to string with Java.

	public static String readFile(String filename) {
		StringBuilder sb = new StringBuilder();
	        FileReader fileReader = new FileReader(filename);
	        BufferedReader bufferedReader = new BufferedReader(fileReader);
	        String line = null;
	        while ((line = bufferedReader.readLine()) != null) {
	            sb.append(line + "\n");
		} catch(Exception e) { e.printStackTrace(); }
        return sb.toString();

Thank you for your interest in my site. If you find the information provided on this site useful, please consider making a donation to help continue development!

PayPal will open in a new tab.

Related Posts

Tagged with:  

Leave a Reply