Java InputStreamReader Read load(String fileName)

Here you can find the source of load(String fileName)

Description

load

License

Open Source License

Declaration

public static char[] load(String fileName) 

Method Source Code


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

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

import java.util.Arrays;

public class Main {
    public static char[] load(String fileName) {
        File file = new File(fileName);
        final int size = (int) file.length();
        char[] buffer = new char[size];
        try (InputStreamReader in = new InputStreamReader(new FileInputStream(file))) {
            int readSize = in.read(buffer);
            if (readSize < size) {
                buffer = Arrays.copyOf(buffer, readSize);
            }//from ww w  .  j a va  2  s  .co  m
            return buffer;
        } catch (IOException e) {
        }
        return null;
    }
}

Related

  1. load(File file, String encoding)
  2. load(final File file, final Class clazz)
  3. loadAsText(InputStream in, String encoding, int bufferSize)
  4. readFile(Class cl, String filename)
  5. readFile(Class cls, String filename)
  6. readFile(ClassLoader classloader, String filename)