Java URL Load readData(String url)

Here you can find the source of readData(String url)

Description

read Data

License

Apache License

Declaration

public static String readData(String url) 

Method Source Code


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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    public static String readData(String url) {
        StringBuilder data = new StringBuilder();
        try {//from   w ww . j a  v a  2  s  . c  o m
            BufferedReader in = new BufferedReader(new InputStreamReader(new URL(url).openStream()));

            String line;
            while ((line = in.readLine()) != null) {
                data.append(line);
            }
            in.close();
        } catch (MalformedURLException e) {
            System.out.println("Malformed URL: " + e.getMessage());
        } catch (IOException e) {
            System.out.println("I/O Error: " + e.getMessage());
        }
        return data.toString();
    }
}

Related

  1. readContentFromFile(URL u, String encoding)
  2. readContents(URL url)
  3. readContentsToArray(URL url)
  4. readContentsToList(URL url)
  5. readContentsToString(URL url)
  6. readFile(URL file)
  7. readFile(URL url)
  8. readFile(URL url)
  9. readFileContent(URL file)