Here you can find the source of getDataFromServer(URL url)
Parameter | Description |
---|---|
url | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static String getDataFromServer(URL url) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2006, 2007 Bug Labs, Inc.. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.buglabs.net/legal/epl_license.html *******************************************************************************/ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; public class Main { /**/*from w w w .ja v a2 s. c o m*/ * @param url * @return Returns data from the server with a given url * @throws IOException */ public static String getDataFromServer(URL url) throws IOException { java.net.URLConnection conn = url.openConnection(); StringBuffer sb = new StringBuffer(); conn.setDoInput(true); conn.setDoOutput(false); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = rd.readLine()) != null) { if (line.trim().length() > 0) { sb.append(line); } } rd.close(); return sb.toString(); } }