Java Text File Read readTextFile(InputStream inStream)

Here you can find the source of readTextFile(InputStream inStream)

Description

read Text File

License

Open Source License

Declaration

public static String readTextFile(InputStream inStream) 

Method Source Code

//package com.java2s;
/**// www  . java  2s. com
 * Copyright (c) 2014 Far Eastone Telecommunications Co., Ltd.
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information of 
 * Far Eastone Telecommunications Co., Ltd. ("Confidential Information"). 
 * 
 * You shall not disclose such Confidential Information and shall use it 
 * only in accordance with the terms of license agreement you entered
 * into with Far Eastone Telecommunications Co., Ltd.
 */

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

public class Main {
    private static final String encoding = "UTF-8";

    public static String readTextFile(InputStream inStream) {
        String content = "";

        try {
            int ca = inStream.available();
            byte[] by = new byte[ca];

            inStream.read(by);
            content = new String(by, encoding);
            inStream.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return content;
    }
}

Related

  1. readFile(String filePath)
  2. readFile(String path)
  3. readTextFile(File file, int max, String ellipsis)
  4. readTextFile(final DataInputStream is)
  5. readTextFile(final String path, final String enc)
  6. readTextFile(String fileName)
  7. readTextFile(String fn)
  8. readTextFileFast(final File file)