Here you can find the source of openReader(String aUrl)
Parameter | Description |
---|---|
aUrl | the url to open a reader to |
Parameter | Description |
---|---|
IOException | if the url could not be read |
public static BufferedReader openReader(String aUrl) throws IOException
//package com.java2s; /*/* w ww . java 2 s.c o m*/ * Copyright 2014 Davy Maddelein. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class Main { /** * convenience method for opening a buffered reader to an url, standard timeout is set to 500 milliseconds * @param aUrl the url to open a reader to * @return the buffered reader for reading the url * @throws IOException if the url could not be read */ public static BufferedReader openReader(String aUrl) throws IOException { URL myURL = new URL(aUrl); HttpURLConnection c = (HttpURLConnection) myURL.openConnection(); c.setConnectTimeout(500); return new BufferedReader(new InputStreamReader(new BufferedInputStream(c.getInputStream()), "UTF-8")); } }