Java File to String fileToString(String filename)

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

Description

file To String

License

Open Source License

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.BufferedReader;

import java.io.FileNotFoundException;
import java.io.FileReader;

import java.io.IOException;

public class Main {
    public static String fileToString(String filename) throws FileNotFoundException, IOException {
        BufferedReader reader = new BufferedReader(new FileReader(filename));
        String line = null;/* www  . j  a v a 2 s.  c  o  m*/
        StringBuilder stringBuilder = new StringBuilder();
        String ls = System.getProperty("line.separator");

        while ((line = reader.readLine()) != null) {
            stringBuilder.append(line);
            stringBuilder.append(ls);
        }

        return stringBuilder.toString();
    }
}

Related

  1. fileToString(String filename)
  2. fileToString(String filename)
  3. fileToString(String fileName)
  4. fileToString(String fileName)
  5. fileToString(String fileName)
  6. fileToString(String filename)
  7. fileToString(String fileName)
  8. fileToString(String fileName)
  9. fileToString(String filename)