使用java读取url网络文件

来源:互联网 发布:淘宝不能用 编辑:程序博客网 时间:2024/05/01 20:38

使用java读取url文件

使用简单的url方法读取网络中的文件,代码如下,一看便知:

import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.net.URL;/** * @author: wangchao.wang * @date: 2015-07-22 14:47:00 */public class Test {    private static final String URL = "www.baidu.com";    public static void main(String[] args) throws IOException {        URL url = new URL(URL);        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));        String s;        while ((s = reader.readLine()) != null) {            System.out.println(s);        }        reader.close();    }}

记在博客中方便查看。

0 0
原创粉丝点击