一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務器之家 - 編程語言 - JAVA教程 - java編寫Http服務器下載工具

java編寫Http服務器下載工具

2019-12-13 10:49hebedich JAVA教程

這篇文章主要介紹了java編寫Http服務器下載工具的方法,工具很簡單,功能也很簡單,代碼就更簡潔了,卻非常實用,有需要的小伙伴參考下吧。

這個工具比較簡單,用于配合另外一個工具進行文件傳送,廢話少說,上代碼

java" id="highlighter_777643">
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import java.net.URL;
import java.net.URLConnection;
import java.io.File;
import java.io.InputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
 
import org.apache.commons.io.FileUtils;
 
public class HttpUtil{
  private String httppath = "";
 
  public void setHttpPath(String httppath){
    this.httppath = httppath;
  }
 
  public String getHttpPath(){
    return this.httppath;
  }
 
  public HttpUtil(String httppath){
    this.httppath = httppath;
  }
 
  public InputStream getStream(String url){
    InputStream inStream = null;
    try{
      URL httpurl = new URL(url);
      URLConnection conn = httpurl.openConnection();
      inStream = conn.getInputStream();
    }catch (Exception e){
      e.printStackTrace();
      return null;
    }
    return inStream;
  }
 
  public int downLoad(String url,String localName ,int lines) throws FileNotFoundException, IOException{
    FileOutputStream fos = null;
    InputStream inStream = null;
    int ret = 0;
    try{
      URL httpurl = new URL(url);
      URLConnection conn = httpurl.openConnection();
      inStream = conn.getInputStream();
      fos = new FileOutputStream(localName);
      byte[] b = new byte[102400];
      int j = 0;
      while(inStream.read(b) != -1 && lines > 0){
        for(int i = j; i < b.length; i++){
          if(b[i] == '\n'){
            fos.write(b, j, i - j + 1);
            lines--;
            if(lines <= 0){
              break;
            }
            j = i + 1;
            continue;
          }
        }
      }
    }catch (Exception e){
      e.printStackTrace();
      ret = -1;
    }finally {
      fos.close();
      inStream.close();
      return ret;
    }
  }
 
  public static void main(String[] args){
    String httppath = "";
    int lines = 0;
    String localName = "";
    try{
      httppath = args[0];
      localName = args[1];
      lines = Integer.parseInt(args[2]);
    }catch (Exception e){
      e.printStackTrace();
      return;
    }
    try{
      HttpUtil hu = new HttpUtil(httppath);
      hu.downLoad(hu.getHttpPath(),localName ,lines);
    }catch (Exception e){
      e.printStackTrace();
    }
  }
}

這個工具實現了從HTTP服務器上下載指定行數的文件,并且不會因為編碼的問題引起下載的文件內容亂碼
三個工具已經搞定,下一次就是把這三個工具結合起來將HTTP、FTP的文件轉移到HDFS上

hadoop工具


ftp工具

以上就是本文所述的全部內容了,希望大家能喜歡。

請您花一點時間將文章分享給您的朋友或者留下評論。我們將會由衷感謝您的支持!

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 免费高清资源黄网站在线观看 | 被强上后我成瘾了小说 | 欧美日韩在线观看区一二 | 国产小视频在线免费 | 拍拍叫痛的无挡视频免费 | 狠狠色96视频 | 国产午夜亚洲精品一区网站 | 精品国产影院 | 成人综合网站 | 五月天色小说 | 四虎论坛| ysav67| 高h折磨调教古代 | 美女私人影院 | 免费高清资源黄网站在线观看 | 日韩特级片 | 好爽视频 | 久久久乱码精品亚洲日韩 | 国产精品久久国产精品99 gif | 911福利视频| 亚洲欧美日韩成人 | 成人国产精品一级毛片视频 | 肉文高h调教 | 四虎在线网站 | 91成人免费视频 | 黑人疯狂巨大xxoo | 射18p| 亚洲女人国产香蕉久久精品 | 我半夜摸妺妺的奶C了她 | 国产suv精品一区二区四区三区 | 日本激情网 | www.一区二区三区.com | 人人爽人人草 | 成人伊人亚洲人综合网站222 | 亚洲无限 | 无码11久岁箩筣 | 亚洲国产在线99视频 | 午夜国产精品视频在线 | 国产一区二区三区免费在线视频 | 午夜深情在线观看免费 | 国产日韩精品欧美一区 |