Java BufferedReader Read loadIntoString(InputStream is)

Here you can find the source of loadIntoString(InputStream is)

Description

Writes all contents of the given InputStream to a String

License

Open Source License

Declaration

public static String loadIntoString(InputStream is) throws IOException 

Method Source Code

//package com.java2s;
/* /*from  w  ww .j a  va2s .  c  om*/
 GeoGebra - Dynamic Mathematics for Everyone
 http://www.geogebra.org
    
 This file is part of GeoGebra.
    
 This program is free software; you can redistribute it and/or modify it 
 under the terms of the GNU General Public License as published by 
 the Free Software Foundation.
     
 */

import java.io.BufferedReader;

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

public class Main {
    /**
     * Writes all contents of the given InputStream to a String
     */
    public static String loadIntoString(InputStream is) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF8"));
        StringBuilder sb = new StringBuilder();

        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return sb.toString();
    }
}

Related

  1. loadEnrichmentHits(File file)
  2. loadIgnorList()
  3. loadInputStream(InputStream inputStream)
  4. loadInt(BufferedReader br)
  5. loadIntegersFromFile(String filename)
  6. loadJCC()
  7. loadJson(String path)
  8. loadKey(String filename)
  9. loadLastExpInfo(String lastExpFileName)