`
ericwzc
  • 浏览: 12028 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

java下载文件

 
阅读更多

*Stream ----- byte oriented
*der       ----- char oriented

Buffered*----- add buffer
Print*     ----- format

 

		URL url = new URL(
				"http://docs.oracle.com/javase/tutorial/networking/sockets/examples/KnockKnockServer.java");
		URLConnection uc = url.openConnection();
		InputStream in = null;
		OutputStream out = null;

		try {
			in = new BufferedInputStream(uc.getInputStream());
			out = new BufferedOutputStream(new FileOutputStream("test1"));
			int c;
			while ((c = in.read()) != -1) {
				out.write(c);
			}
		} catch (Exception ex) {
			// do sth
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.close();
			}
		}
 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics