摘要:這個工具比較簡單,用于配合另外一個工具進行文件傳送廢話少說,上代碼這個工具實現(xiàn)了從服務(wù)器上下載指定行數(shù)的文件,并且不會因為編碼的問題引起下載的文件內(nèi)容亂碼三個工具已經(jīng)搞定,下一次就是把這三個工具結(jié)合起來將的文件轉(zhuǎn)移到上工具工具
這個工具比較簡單,用于配合另外一個工具進行文件傳送,廢話少說,上代碼
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] == " "){ 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(); } } }
這個工具實現(xiàn)了從HTTP服務(wù)器上下載指定行數(shù)的文件,并且不會因為編碼的問題引起下載的文件內(nèi)容亂碼
三個工具已經(jīng)搞定,下一次就是把這三個工具結(jié)合起來將HTTP、FTP的文件轉(zhuǎn)移到HDFS上
hadoop工具
ftp工具
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://www.ezyhdfw.cn/yun/64286.html
摘要:是面向?qū)ο笳Z言這意味著支持面向?qū)ο蟮娘L格或代碼封裝在對象的編程技術(shù)。在上執(zhí)行命令,就可以進入到的交互模式,并顯示出版本等信息。選擇的版本,需要下載安裝包,然后進行安裝。 一、Python簡介 Python 是一種解釋型語言: 這意味著開發(fā)過程中沒有了編譯這個環(huán)節(jié)。類似于PHP和Perl語言。 Python 是交互式語言: 這意味著,您可以在一個Python提示符,直接互動執(zhí)行寫你的程...
摘要:,將類或枚舉類型映射到模式類型,控制字段或?qū)傩缘男蛄谢?。表示將自動綁定類中的每個非靜態(tài)的非瞬態(tài)的由標注字段到。,對于數(shù)組或集合即包含多個元素的成員變量,生成一個包裝該數(shù)組或集合的元素稱為包裝器。 在經(jīng)過前面兩篇文章的學習,我已經(jīng)能夠熟練創(chuàng)建一個正常運行的spring-ws的webservice服務(wù),大多數(shù)接口,都是要有返回數(shù)據(jù),所以這篇文章就是學習spring-ws怎么實現(xiàn)返回數(shù)據(jù) 實...
閱讀 2176·2021-10-11 10:59
閱讀 996·2021-09-23 11:21
閱讀 3743·2021-09-06 15:02
閱讀 1689·2021-08-19 10:25
閱讀 3513·2021-07-30 11:59
閱讀 2461·2019-08-30 11:27
閱讀 2652·2019-08-30 11:20
閱讀 3044·2019-08-29 13:15