Here you can find the source of getText(String url)
Parameter | Description |
---|---|
url | The url to connect to. |
Parameter | Description |
---|---|
Exception | This exception is thrown when there was a problem connecting to the URL |
public static String[] getText(String url) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; public class Main { /**//from www. j av a2 s . c o m * Returns the response from the given URL as an array of lines. * @param url * The url to connect to. * @return * A response string from the server. * @throws Exception * This exception is thrown when there was a problem connecting to the URL */ public static String[] getText(String url) throws Exception { URL website = new URL(url); URLConnection connection = website.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); ArrayList<String> lines = new ArrayList<String>(); String inputLine; while ((inputLine = in.readLine()) != null) lines.add(inputLine); in.close(); return lines.toArray(new String[lines.size()]); } }