Here you can find the source of getContent(final String urlString)
Parameter | Description |
---|---|
urlString | URL to get the contents of |
public static String getContent(final String urlString)
//package com.java2s; /*/*from w w w. j a v a 2 s . c om*/ * This file is part of SpaceModule (http://spacebukkit.xereo.net/). * * SpaceModule is free software: you can redistribute it and/or modify it under the terms of the * Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA) license as published by the Creative * Common organization, either version 3.0 of the license, or (at your option) any later version. * * SpaceBukkit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA) license for more details. * * You should have received a copy of the Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA) * license along with this program. If not, see <http://creativecommons.org/licenses/by-nc-sa/3.0/>. */ import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; public class Main { /** * Gets the contents of a URL * @param urlString URL to get the contents of * @return Contents of the URL */ public static String getContent(final String urlString) { try { final URL url = new URL(urlString); final URLConnection urlConnection = url.openConnection(); final BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String inputLine = "", content = ""; while ((inputLine = reader.readLine()) != null) content += inputLine; reader.close(); return content; } catch (final Exception e) { } return null; } }