Java URL Load loadURLToString(String url, String EOL)

Here you can find the source of loadURLToString(String url, String EOL)

Description

Loads a web page from an URL to a string.

License

Apache License

Parameter

Parameter Description
url address of the page
EOL End-of-line string to put into the resulting string

Exception

Parameter Description
FileNotFoundException an exception
IOException an exception

Declaration

public static String loadURLToString(String url, String EOL) throws FileNotFoundException, IOException 

Method Source Code


//package com.java2s;
/*//w  w  w. j  a v  a  2  s.  c  o m
 * Copyright 2005-2009 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.io.InputStreamReader;

import java.net.URL;

public class Main {
    /**
     * Loads a web page from an URL to a string.
     * 
     * @param url
     *          address of the page
     * @param EOL
     *          End-of-line string to put into the resulting string
     * @return
     * @throws FileNotFoundException
     * @throws IOException
     */
    public static String loadURLToString(String url, String EOL) throws FileNotFoundException, IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader((new URL(url)).openStream()));
        String result = "";
        String str;
        while ((str = in.readLine()) != null) {
            result += str + EOL;
        }
        in.close();
        return result;
    }
}

Related

  1. loadURL(String urlDesc)
  2. loadURL(URL url)
  3. loadURL(URL url)
  4. loadUrlIntoByteArray(String urlString)
  5. loadUrlToList(URL iUrl)
  6. read(String url)
  7. read(URL file)
  8. read(URL url, String charsetName)
  9. readAsString(URL url)