Java URL to InputStream getUrlContents(URL url)

Here you can find the source of getUrlContents(URL url)

Description

get Url Contents

License

Apache License

Declaration

public static String getUrlContents(URL url) throws IOException 

Method Source Code


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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;

public class Main {
    public static String getUrlContents(URL url) throws IOException {
        BufferedReader bReader = null;
        String contents = null;/*from   w  ww  . ja  v a 2  s. co  m*/
        try {
            StringBuilder buf = new StringBuilder();
            bReader = new BufferedReader(new InputStreamReader(url.openStream()));

            String inputLine;
            while ((inputLine = bReader.readLine()) != null) {
                buf.append(inputLine);
            }
            contents = buf.toString();
        } finally {
            if (bReader != null)
                bReader.close();
        }
        return contents;
    }
}

Related

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