更新时间:2024-12-10 GMT+08:00
读Alluxio文件
功能简介
获取Alluxio上某个指定文件的内容。
代码样例
用于获取Alluxio上某个指定文件的内容。
以下为部分代码片段:
/**
* read file
* @throws java.io.IOException
*/
private void read() throws IOException {
AlluxioURI path = new AlluxioURI(testFilePath);
FileInStream in = null;
try{
in = fSystem.openFile(path);
byte[] buffer = new byte[1024];
int len;
String content = "";
while((len = in.read(buffer)) != -1){
String bufferStr = new String(buffer,0, len);
content += bufferStr;
}
System.out.println(content);
}
catch (Exception e){
System.out.println("Failed to read file. Exception:" + e);
}
finally {
close(in);
}
}
父主题: 开发Alluxio应用