Java URL Load readJsonFromUrl(String urlString)

Here you can find the source of readJsonFromUrl(String urlString)

Description

Opens a buffered reader, reads the URL and closes the buffered reader.

License

Apache License

Parameter

Parameter Description
urlString a parameter

Exception

Parameter Description
Exception an exception

Declaration

public static JsonObject readJsonFromUrl(String urlString) throws IOException 

Method Source Code


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

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

public class Main {
    public static Gson gson = new Gson();

    /**// www .j a  va2 s . c  o  m
     * Opens a buffered reader, reads the URL and closes the buffered reader.
     * @param urlString
     * @return
     * @throws Exception
     */
    public static JsonObject readJsonFromUrl(String urlString) throws IOException {
        InputStreamReader inStream = null;
        try {
            URL url = new URL(urlString);
            inStream = new InputStreamReader(url.openStream());
            return gson.fromJson(inStream, JsonObject.class);
        } finally {
            if (inStream != null)
                inStream.close();
        }
    }
}

Related

  1. readFromURL(URL url)
  2. readGOMappingFile(URL filename, Set secondAttributeList)
  3. readHttpBytes(String url)
  4. readHttpFile(final String urlStr)
  5. readInteger(URL src, int radix)
  6. readLines(final String url)
  7. readLines(final URL url)
  8. readLines(URL url)
  9. readLinesTrimmedNoCommentFromUrl(final URL fileUrl, final String commentString)

  10. HOME | Copyright © www.java2s.com 2016