冷面阎罗

低调做人&&高调做事
随笔 - 208, 文章 - 3, 评论 - 593, 引用 - 0
数据加载中……

有关java远程读取文件的方法

 1package word;
 2
 3import java.io.FileOutputStream;
 4import java.io.InputStream;
 5import java.net.HttpURLConnection;
 6
 7public class FileRead {
 8
 9public static void main(String[] args) {
10    java.net.URL urlfile = null
11    HttpURLConnection httpUrl = null
12
13    try {
14
15            // 连接指定的网络资源,获取网络输入流
16            urlfile = new java.net.URL(
17                    "http://10.142.202.12/ftp/Y0131000000168/D0011000006537.jpg");
18            httpUrl = (HttpURLConnection) urlfile.openConnection();
19            httpUrl.connect();
20            int bytesum = 0;
21            int byteread = 0;
22            InputStream inStream = httpUrl.getInputStream();
23            FileOutputStream fs = new FileOutputStream("c:/1.jpg");
24            byte[] buffer = new byte[1444];
25            while ((byteread = inStream.read(buffer)) != -1{
26                bytesum += byteread;
27                fs.write(buffer, 0, byteread);
28            }
    
29            
30        }
 catch (Exception e) {
31
32        }
 
33}

34}

35

posted on 2007-04-03 08:57 冷面阎罗 阅读(1428) 评论(0)  编辑  收藏 所属分类: java


只有注册用户登录后才能发表评论。


网站导航: