Java Text File Read getFileContentAsString(InputStream inputStream)

Here you can find the source of getFileContentAsString(InputStream inputStream)

Description

Reads the content of a given file as a String and returns it.

License

Open Source License

Return

the content of the given file as a String

Declaration

public static String getFileContentAsString(InputStream inputStream) throws IOException 

Method Source Code


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

import java.io.IOException;
import java.io.InputStream;

public class Main {
    /** Reads the content of a given file as a String and returns it.
     * @return the content of the given file as a String */
    public static String getFileContentAsString(InputStream inputStream) throws IOException {
        String data = "";
        byte[] buffer = new byte[1024];
        int numRead = -1;

        while (true) {
            numRead = inputStream.read(buffer);
            if (numRead == 1024) {
                data += new String(buffer);
            } else {
                if (numRead != -1)
                    data += new String(buffer, 0, numRead);
                break;
            }/*from w  w w .ja  v a  2s.c  o  m*/
        }

        return data;

    }
}

Related

  1. fileContentsToString(String file)
  2. getChars(File file)
  3. getChars(Reader r)
  4. getFileContentAsString(File cpfile)
  5. getFileContentAsString(final String filePath)
  6. getFileContentAsString(String path)
  7. getFileContents(Reader reader)
  8. getFileContents(String filePath)
  9. getFileContents(String filePath)