Java File to String fileToString(String filename)

Here you can find the source of fileToString(String filename)

Description

Returns the string representation of a given file.

License

Open Source License

Parameter

Parameter Description
filename The file to turn into a string

Declaration

public static String fileToString(String filename) throws FileNotFoundException, IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    /**/*from www.  j  av a2  s.  c o m*/
     * Returns the string representation of a given file.
     * @param filename The file to turn into a string
     */
    public static String fileToString(String filename) throws FileNotFoundException, IOException {

        StringBuffer sb = new StringBuffer();
        BufferedReader in = new BufferedReader(new FileReader(filename));
        String str;
        while ((str = in.readLine()) != null)
            sb.append(str);
        in.close();
        return sb.toString();
    }
}

Related

  1. fileToString(String file)
  2. fileToString(String file)
  3. fileToString(String file)
  4. fileToString(String file, String encoding)
  5. FileToString(String file_name)
  6. fileToString(String filename)
  7. fileToString(String fileName)
  8. fileToString(String fileName)
  9. fileToString(String fileName)