學習課件 (私密)通過API IO操作HDFS

2021-09-27 04:34:37 字數 2975 閱讀 7205

3.2 通過api操作hdfs

3.2.1 hdfs獲取檔案系統

1)詳細**

/*** 列印本地hadoop位址值

* io的方式寫**

*/@test

public void intihdfs() throws ioexception 3.2.2 hdfs檔案上傳

/*** 上傳**

* 注意:如果上傳的內容大於128mb,則是2塊

*/@test

public void putfiletohdfs() throws exception 3.2.4 hdfs目錄建立

/*** hadoop fs -mkdir /xinshou

*/@test

public void mkmdirhdfs() throws exception 3.2.5 hdfs資料夾刪除

/*** hadoop fs -rm -r /檔案

*/@test

public void deletehdfs() throws exception 3.2.6 hdfs檔名更改

@test

public void renameathdfs() throws exception3.2.7 hdfs檔案詳情檢視

檢視檔名稱、許可權、長度、塊資訊

/*** 檢視【檔案】名稱、許可權等

*/@test

public void readlistfiles() throws exception

}system.out.println("------------------華麗的分割線----------------");

}3.2.8 hdfs檔案和資料夾判斷

/*** 判斷是否是個檔案還是目錄,然後列印

* @throws exception

*/@test

public void judge() throws exception else

}}3.3 通過io流操作hdfs

3.3.1 hdfs檔案上傳

/*** io流方式上傳

** @throws urisyntaxexception

* @throws filenotfoundexception

* @throws interruptedexception

*/@test

public void putfiletohdfsio() throws urisyntaxexception, ioexception, interruptedexception catch (ioexception e) finally

}

//2.獲取檔案系統

filesystem fs = filesystem.get(new uri("hdfs://bigdata111:9000"), conf, "root");

//3.讀取路徑

path readpath = new path("hdfs://bigdata111:9000/plus/sogou.txt");

//4.輸入

fsdatainputstream fis = fs.open(readpath);

//5.輸出到控制台

//inputstream in 輸入

//outputstream out 輸出

//int buffsize 緩衝區

//boolean close 是否關閉流

ioutils.copybytes(fis,system.out,4 * 1024 ,true);

}

//2.獲取檔案系統

filesystem fs = filesystem.get(new uri("hdfs://bigdata111:9000"), conf, "root");

//3.輸入

path path = new path("hdfs://bigdata111:9000/plus/hadoop-2.7.2.rar");

fsdatainputstream fis = fs.open(path);

//4.輸出

fileoutputstream fos = new fileoutputstream("f:\\date\\readfileseek\\a1");

//5.流對接

byte buf = new byte[1024];

for (int i = 0; i < 128 * 1024; i++)

//6.關閉流

ioutils.closestream(fos);

ioutils.closestream(fis);

}

//2.獲取檔案系統

filesystem fs = filesystem.get(new uri("hdfs://bigdata111:9000"), conf, "root");

//3.輸入

path path = new path("hdfs://bigdata111:9000/plus/hadoop-2.7.2.rar");

fsdatainputstream fis = fs.open(path);

//4.輸出

fileoutputstream fos = new fileoutputstream("f:\\date\\readfileseek\\a2");

//5.定位偏移量/offset/游標/讀取進度 (目的:找到第一塊的尾巴,第二塊的開頭)

fis.seek(128 * 1024 * 1024);

//6.流對接

ioutils.copybytes(fis, fos, 1024);

//7.關閉流

ioutils.closestream(fos);

ioutils.closestream(fis);

}

3)合併檔案

在window命令視窗中執行

type a2 >> a1 然後更改字尾為rar即可

fabric私密資料學習筆記

乙個是真正的key,value,它被存在 peer的私密資料庫 private state 中。另一部分為公共資料,它是真實的私密資料key,value 雜湊後的值 hash key hash value 它被存在普通的peer資料庫中 state orderer端可以拿到該值。沒有被分配私密資料許...

php學習 函式 課件

重用 include require 這兩個函式都是用來引用檔案的,區別是當處理失敗時include 產生乙個警告而require 是乙個緻密錯誤 include once require once 這兩個函式與include 與require 是一樣的 區別是include once與requir...

一套很好的C 學習課件

c 學習網頁課件鏈結 第一講 c 簡介 第二講 c 對c的擴充 1 第三講 c 對c的擴充 2 第四講 程式設計方法 第五講 類的成員 第六講 物件的簡單應用 第七講 構造析構函式 第八講 陣列與指標 第九講 資料的保護 第十講 賦值和複製 第十一講 運算子過載 第十二講 過載應用 第十三講 資料間...