當前位置:編程學習大全網 - 源碼下載 - 往hdfs上追加數據

往hdfs上追加數據

妳的hadoop參數配置正確了嗎?在hdfs-site.xml中把以下屬性修改為true才可以。

<property>

<name>dfs.support.append</name>

<value>true</value>

</property>

下面有壹段測試代碼,妳可以參考壹下:

package com.wyp;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.fs.FileSystem;

import org.apache.hadoop.fs.Path;

import org.apache.hadoop.io.IOUtils;

import java.io.*;

import java.net.URI;

public class AppendContent {

public static void main(String[] args) {

String hdfs_path = "hdfs://mycluster/home/wyp/wyp.txt";//文件路徑

Configuration conf = new Configuration();

conf.setBoolean("dfs.support.append", true);

String inpath = "/home/wyp/append.txt";

FileSystem fs = null;

try {

fs = FileSystem.get(URI.create(hdfs_path), conf);

//要追加的文件流,inpath為文件

InputStream in = new

BufferedInputStream(new FileInputStream(inpath));

OutputStream out = fs.append(new Path(hdfs_path));

IOUtils.copyBytes(in, out, 4096, true);

} catch (IOException e) {

e.printStackTrace();

}

}

}

  • 上一篇:指標源碼 大智慧FNC.通達信TNI文件怎樣安裝到軟件裏
  • 下一篇:了解IBM發展史
  • copyright 2024編程學習大全網