Java ByteArrayOutputStream Write loadAsText(Class cls, String name)

Here you can find the source of loadAsText(Class cls, String name)

Description

load As Text

License

Open Source License

Declaration

public static String loadAsText(Class cls, String name) 

Method Source Code

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

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

public class Main {
    public static String loadAsText(Class cls, String name) {
        byte[] buffer = new byte[1024];
        int nr;//ww  w  .  jav a2  s.  co  m
        try (InputStream in = cls.getResourceAsStream(name);
                ByteArrayOutputStream out = new ByteArrayOutputStream()) {
            while ((nr = in.read(buffer)) > 0) {
                out.write(buffer, 0, nr);
            }

            return new String(out.toByteArray(), "UTF-8");
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }
}

Related

  1. load(InputStream is)
  2. load(InputStream is, boolean close)
  3. load(String fileName)
  4. loadAFileToString(File f)
  5. loadAsciiTxt()
  6. loadBinFile(java.io.File f)
  7. loadFully(final InputStream aStream)
  8. loadIfileAsBytes(final IFile ifile)
  9. loadIntoMemory(InputStream is)