Here you can find the source of loadURLToString(String url, String EOL)
Parameter | Description |
---|---|
url | address of the page |
EOL | End-of-line string to put into the resulting string |
Parameter | Description |
---|---|
FileNotFoundException | an exception |
IOException | an exception |
public static String loadURLToString(String url, String EOL) throws FileNotFoundException, IOException
//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; } }