HDFS文件追加append

HDFS中文件可以追加写,步骤如下:

1、配置集群(hdfs-site.xml),必须配置才可以
  <property>
        <name>dfs.support.append</name>
        <value>true</value>
  </property>

2、API实现

String hdfs_path= "hdfs://ip:xx/file/fileuploadFileName";//文件路径
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create(hdfs_path), conf);
InputStream in = new BufferedInputStream(new FileInputStream(file));//要追加的文件流,file为文件
OutputStream out = fs.append(new Path(hdfs_path));
IOUtils.copyBytes(in, out, 4096, true);

相关阅读:

相关推荐