Java File to String fileToStringOneLine(String path)

Here you can find the source of fileToStringOneLine(String path)

Description

file To String One Line

License

Open Source License

Declaration

public static String fileToStringOneLine(String path) 

Method Source Code


//package com.java2s;
// {LICENSE}/*from   w  w w  .jav  a2  s .  co  m*/

import java.io.BufferedReader;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static String fileToStringOneLine(String path) {
        String string = new String();
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path)));

            String line;
            while ((line = reader.readLine()) != null) {
                string += line;
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return string;
    }
}

Related

  1. fileToString(String strPath)
  2. fileToStringArray(String fileName)
  3. fileToStringBuffer(File file)
  4. fileToStringList(File f)
  5. fileToStringList(String filePath)
  6. readFileAsString(String filePath)
  7. readFileAsString(String filePath)
  8. readFileAsString(String filePath)
  9. readFileAsString(String filePath)