HDFS環(huán)境準(zhǔn)備

1.配置Maven


2.修改本地倉庫位置

3.配置鏡像地址

4.pom文件配置

<dependencies>

<dependency>

? ? ? ? ? ? <groupId>org.apache.hadoop</groupId>

? ? ? ? ? ? <artifactId>hadoop-common</artifactId>

? ? ? ? ? ? <version>2.8.4</version>

? ? ? ? </dependency>

? ? ? ? <dependency>

? ? ? ? ? ? <groupId>org.apache.hadoop</groupId>

? ? ? ? ? ? <artifactId>hadoop-hdfs</artifactId>

? ? ? ? ? ? <version>2.8.4</version>

? ? ? ? </dependency>

? ? ? ? <dependency>

? ? ? ? ? ? <groupId>org.apache.hadoop</groupId>

? ? ? ? ? ? <artifactId>hadoop-client</artifactId>

? ? ? ? ? ? <version>2.8.4</version>

? ? ? ? </dependency>

? ? ? ? <dependency>

? ? ? ? ? ? <groupId>org.projectlombok</groupId>

? ? ? ? ? ? <artifactId>lombok</artifactId>

? ? ? ? ? ? <version>1.16.10</version>

? ? ? ? </dependency>

? ? ? ? <dependency>

? ? ? ? ? ? <groupId>log4j</groupId>

? ? ? ? ? ? <artifactId>log4j</artifactId>

? ? ? ? ? ? <version>1.2.17</version>

? ? ? ? ? ? 下載插件

? ? ? ? </dependency>

? ? ? ? <dependency>

? ? ? ? ? ? <groupId>org.slf4j</groupId>

? ? ? ? ? ? <artifactId>slf4j-api</artifactId>

? ? ? ? ? ? <version>1.7.7</version>

? ? ? ? </dependency>

? ? ? ? <!-- https://mvnrepository.com/artifact/junit/junit -->

? ? ? ? <dependency>

? ? ? ? ? ? <groupId>junit</groupId>

? ? ? ? ? ? <artifactId>junit</artifactId>

? ? ? ? ? ? <version>4.12</version>

? ? ? ? ? ? <scope>test</scope>

? ? ? ? </dependency>

? </dependencies>

編寫使用Hadoop

public class HdfsClientDemo1 {

public static void main(String[] args) throws Exception {

// 1 獲取文件系統(tǒng)

Configuration configuration = new Configuration();

// 配置在集群上運(yùn)行

configuration.set("fs.defaultFS", "hdfs://bigdata111:9000");

FileSystem fileSystem = FileSystem.get(configuration);

// 直接配置訪問集群的路徑和訪問集群的用戶名稱

// FileSystem fileSystem = FileSystem.get(new URI("hdfs://bigdata111:9000"),configuration, "itstar");

// 2 把本地文件上傳到文件系統(tǒng)中

fileSystem.copyFromLocalFile(new Path("f:/hello.txt"), new Path("/hello1.copy.txt"));

// 3 關(guān)閉資源

fileSystem.close();

System.out.println("over");}}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容