首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

URL简略例子

2012-10-12 
URL简单例子代码例子:package com.testimport java.io.FileOutputStreamimport java.io.InputStreamimp

URL简单例子
代码例子:

package com.test;import java.io.FileOutputStream;import java.io.InputStream;import java.io.OutputStream;import java.net.URL;public class URLConnectionTest{public static void main(String[] args) throws Exception{URL url = new URL("http://www.infoq.com");InputStream in = url.openStream();OutputStream os = new FileOutputStream("C:/3.txt");byte[] buffer = new byte[2048];int length = 0;while (-1 != (length = in.read(buffer, 0, buffer.length))){//String str = new String(buffer,0,length);//System.out.println(str);os.write(buffer,0,length);}os.close();in.close();}}

热点排行