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