我是hdfs的新手。当我尝试写入hdfs文件时,我收到以下消息:
[警告]org.apache.hadoop.hdfs.dfsclient-datastreamer exception>java.io.ioexception:无法创建新块]。响应码是200,
但当读取文件内容时,这是空的。这是我的密码:
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);
}
}
}
欢迎提出任何建议。提前谢谢!
暂无答案!
目前还没有任何答案,快来回答吧!