Java URL to InputStream openFileOrURL(String fileNameOrUrl)

Here you can find the source of openFileOrURL(String fileNameOrUrl)

Description

open File Or URL

License

BSD License

Declaration

public static InputStream openFileOrURL(String fileNameOrUrl) throws IOException 

Method Source Code

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

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    public static InputStream openFileOrURL(String fileNameOrUrl) throws IOException {
        try {/*from  ww  w . j av a 2s  .  co  m*/
            URL url = new URL(fileNameOrUrl);
            return url.openStream();
        } catch (MalformedURLException mfe) {
            InputStream str = new FileInputStream(fileNameOrUrl);
            return str;
        }
    }
}

Related

  1. getInputStreamReader(URL url)
  2. getUrlContents(String url)
  3. getUrlContents(String urlString)
  4. getUrlContents(String urlString)
  5. getUrlContents(URL url)
  6. openFileOrURL(String name)
  7. openInputStream(URL url)
  8. openStream(String urlStr)
  9. openStream(URL url)