Java Text File Read by Charset reader(Class baseClass, String resourceName, Charset charset)

Here you can find the source of reader(Class baseClass, String resourceName, Charset charset)

Description

reader

License

Apache License

Declaration

static public Reader reader(Class<?> baseClass, String resourceName,
        Charset charset) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.*;

import java.net.URL;
import java.nio.charset.Charset;

public class Main {

    static public Reader reader(Class<?> baseClass, String resourceName,
            Charset charset) throws IOException {
        return new InputStreamReader(inputStream(baseClass, resourceName),
                charset);//w  w  w.jav  a 2  s . c o m
    }

    static public InputStream inputStream(Class<?> baseClass,
            String resourceName) throws IOException {
        URL url = baseClass.getResource(resourceName);
        if (url == null) {
            throw new FileNotFoundException(String.format(
                    "Resource file is not found. %s", resourceName));
        }
        return url.openStream();
    }
}

Related

  1. readAllText(File file, Charset charset)
  2. readAllText(File file, Charset charset)
  3. readAsString(InputStream in, Charset charset)
  4. readAsString(InputStream is, CharsetDecoder decoder)
  5. readCharsWithEncoding(File file, Charset charset)
  6. reader(InputStream in, String charsetName)
  7. readerBuffered(final File file, final Charset charset)
  8. readFile(Bundle bundle, String path, Charset cs)
  9. readFile(File f, Charset chst)