`
lippeng
  • 浏览: 450790 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

从HTTP服务器上下载文件

阅读更多

从Http服务器上下载个文件到本地。写了一点点代码,认为是能跑了,贴出来,备忘。

 

package com.lippeng.helloworld;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

public class HelloWorld {

    public static void main(String[] args) throws IOException {

	String path = "http://172.21.153.58:9090/TFTP/run.bat";
	URL url = new URL(path);

	InputStream inputStream = url.openStream();
	OutputStream outputStream = new FileOutputStream("run.bat");

	byte[] b = new byte[1];
	int count = inputStream.read(b);
	while (count != -1) {
	    outputStream.write(b, 0, count);
	    count = inputStream.read(b);
	}

	inputStream.close();
	outputStream.close();
    }
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics