Java Path File Read nio openBufferedReader(String pathOrUrl)

Here you can find the source of openBufferedReader(String pathOrUrl)

Description

open Buffered Reader

License

Open Source License

Declaration

public static BufferedReader openBufferedReader(String pathOrUrl) throws IOException 

Method Source Code


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

import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;

public class Main {
    private static final int TIMEOUT = 3000;

    public static BufferedReader openBufferedReader(String pathOrUrl) throws IOException {
        InputStream inputStream;/* w  ww. j av  a  2 s  .  c  om*/
        if (isRemote(pathOrUrl)) {
            URL url = new URL(pathOrUrl);
            inputStream = openConnection(url).getInputStream();
        } else {
            inputStream = new FileInputStream(pathOrUrl);
        }
        return new BufferedReader(new InputStreamReader(inputStream, Charset.defaultCharset()));
    }

    public static boolean isRemote(final String path) {
        return path.startsWith("http:") || path.startsWith("https:");
    }

    private static URLConnection openConnection(final URL url) throws IOException {
        URLConnection conn = url.openConnection();
        conn.setReadTimeout(TIMEOUT);
        conn.setDefaultUseCaches(false);
        conn.setUseCaches(false);
        return conn;
    }
}

Related

  1. loadStringsFromFile(String pathToFile)
  2. loadTestPackets(final Path path)
  3. loadTitles(Path rootDir, Set container)
  4. newBufferedReader(Path path)
  5. newBufferedReader(Path path)
  6. openForReadingAndWriting(String filePath)
  7. openResourceReader(Class resourceOrigin, String resourcePath)
  8. read(String aPathString)
  9. read(String filePath)