Java Reader Read loadText(Reader reader, int length)

Here you can find the source of loadText(Reader reader, int length)

Description

load Text

License

Open Source License

Declaration

public static char[] loadText(Reader reader, int length) throws IOException 

Method Source Code


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

import java.io.*;

public class Main {
    public static char[] loadText(Reader reader, int length) throws IOException {
        char[] chars = new char[length];
        int count = 0;
        while (count < chars.length) {
            int n = reader.read(chars, count, chars.length - count);
            if (n <= 0)
                break;
            count += n;/*w  w  w  .  java 2s.c  o m*/
        }
        if (count == chars.length) {
            return chars;
        } else {
            char[] newChars = new char[count];
            System.arraycopy(chars, 0, newChars, 0, count);
            return newChars;
        }
    }
}

Related

  1. loadChars(Reader in)
  2. loadFully(String path)
  3. loadReader(final Reader in, final StringBuffer buffer)
  4. loadReader(java.io.Reader in)
  5. loadResAsString(String res)