考试 现有程序:在命令行中用“ ls_hdfs /user ”命令实现对HDFS文件系统中目录“ /user ”下的文件的文件名、文件块的大小、文件内容长度打印显示,如下图:请填空,实现全部程序功能。 (图像) public class ls_hdfs { static FileSystem fs = null; //连接文件系统 static void init() throws Exception { // 构造一个配置参数对象,设置一个参数:我们要访问的hdfs的URI Configuration conf = new Configuration(); // 指定HDFS文件系统的namenode节点为:192.168.121.134,服务端口为:9000 空1:_________________________________ // 设置客户端身份为:root System.setProperty("HADOOP_USER_NAME", "root"); // 通过FileSystem的静态方法获取文件系统客户端对象 空2:_________________________________ } //显示文件列表 static void ListFiles(String dir) throws FileNotFoundException, IllegalArgumentException, IOException { // 获取迭代器对象 while (fileList.hasNext()) { LocatedFileStatus fileStatus = fileList.next(); // 打印当前文件名 String fileName=fileStatus.getPath().getName(); 空4:_________________________________ // 打印当前文件块大小 空5:_________________________________ System.out.println(fileBlock); // 打印当前文件内容长度 Long fileLong=fileStatus.getLen(); System.out.println(fileLong); } //关闭文件系统 空6:_________________________________ } public static void main(String[] args) throws Exception { //连接HDFS init(); //显示文件列表 空7:_________________________________ } }
时间: 2024-02-10 14:34:49 浏览: 153
空1:conf.set("fs.defaultFS", "hdfs://192.168.121.134:9000");
空2:fs = FileSystem.get(new URI("hdfs://192.168.121.134:9000"), new Configuration());
空4:BlockLocation[] blocks = fileStatus.getBlockLocations(); String fileBlock = ""; for(BlockLocation block : blocks) { fileBlock += block.getLength() + " "; }
空5:String fileBlock = ""; for(BlockLocation block : blocks) { fileBlock += block.getLength() + " "; }
空6:fs.close();
空7:RemoteIterator<LocatedFileStatus> fileList = fs.listFiles(new Path(dir), true); ListFiles(dir);
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![tar](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)