无法写入HDFS

时间:2015-10-20 09:57:27

标签: java hadoop hdfs

我是HDFS的新手。当我尝试写入HDFS文件时,我收到以下内容:

  

[WARN] org.apache.hadoop.hdfs.DFSClient - DataStreamer Exception> java.io.IOException:无法创建新块]。响应代码为200,

但是当读取文件内容时,这是null。这是我的代码:

public void writeFile(FileSystem fs, String destination) throws IOException {

    Path workingDir = fs.getWorkingDirectory();
    Path newFilePath = new Path("/" + destination);
    newFilePath = Path.mergePaths(workingDir, newFilePath);

    FsPermission fsPermission = new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL);

    StringBuilder sb = new StringBuilder();
    for (int i = 1; i <= 5; i++) {
        sb.append("Data");
        sb.append(i);
        sb.append("\n");
    }
    byte[] byt = sb.toString().getBytes();

    FSDataOutputStream fsOutStream = null;
    try {
        fsOutStream = fs.create(fs, newFilePath, fsPermission);

        fsOutStream.write(byt);

    } catch (Throwable e) {
        log.error("Error while creating file in Hdfs",e);
    } finally {
        try {
            if (fsOutStream != null) {
                fsOutStream.close();
            }
        }catch(Throwable e) {
                log.error("Error while closing FSDataOutputStream", e);
        }
    }
}

欢迎任何建议。提前谢谢!

0 个答案:

没有答案