Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Hadoop learning-- FileUtil tool class use-- day04

Shulou Source: shulou.com Published: 2022-06-03 04:50:22 09月30日 Update

Import java.io.ByteArrayOutputStream

Import java.io.FileInputStream

Import java.io.FileOutputStream

Import java.io.InputStream

Import java.net.URL

Import org.apache.hadoop.conf.Configuration

Import org.apache.hadoop.fs.FSDataInputStream

Import org.apache.hadoop.fs.FSDataOutputStream

Import org.apache.hadoop.fs.FileSystem

Import org.apache.hadoop.fs.FsUrlStreamHandlerFactory

Import org.apache.hadoop.fs.Path

Import org.apache.hadoop.io.IOUtils

Import org.junit.Test

Public class append {

/ * *

* append append operation through API

*

* @ author Administrator

*

* [hadoop@hadoop01 ~] $hdfs dfs-chmod-R aquiw / user/hadoop

* [hadoop@hadoop01 ~] $hdfs dfs-ls-R /

*

*

, /

@ Test

Public void appendfile () throws Exception {

/ / create configuration objects, which have a default loading order, first from core-default.xml to the files in the src directory, here

/ / We have given

Configuration conf = new Configuration ()

/ / the distributed file system fs is created through the configuration object of conf. By default, it is the local file system if no file is specified.

FileSystem fs = FileSystem.get (conf)

/ / define a string of URL

String file = "hdfs://hadoop01:9000/user/hadoop/data/hello.txt"

/ / construct a path object from a string of URL

Path path = new Path (file)

FSDataOutputStream out = fs.append (path)

Out.writeChars ("chuck\ r\ n")

System.out.println (out.toString ())

Out.close ()

}

}

Tags: Files objects characters strings systems distributed directories order tools learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn NVidia macOS Docker OPPO Reno