Java File to String FileToString(String file_name)

Here you can find the source of FileToString(String file_name)

Description

File To String

License

Open Source License

Declaration

public static String FileToString(String file_name) throws Exception 

Method Source Code


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

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static String FileToString(String file_name) throws Exception {
        FileInputStream fis = new FileInputStream(file_name);
        return InputStreamToString(fis);
    }/* w w  w. j a va  2  s.co  m*/

    public static String InputStreamToString(InputStream input_stream) throws Exception {
        StringBuilder sb = new StringBuilder();
        BufferedReader br = new BufferedReader(new InputStreamReader(input_stream, "UTF-8"));

        String sBuffer = br.readLine();
        while (sBuffer != null) {
            sb.append(sBuffer);
            sb.append(System.lineSeparator());
            sBuffer = br.readLine();
        }

        return sb.toString();
    }
}

Related

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