hadoop 文件目录操作
来源:互联网 发布:环保部网络举报 编辑:程序博客网 时间:2024/06/07 07:14
可以用bin/Hadoop fs -ls 来读取HDFS上的文件属性信息。
也可以采用HDFS的API来读取。如下:
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.FileStatus;
public class FileInfo
{
public static void main(String[] args) throws Exception
{
if(args.length != 1){
System.out.println("Usage FileInfo <target>");
System.exit(1);
}
Configuration conf = new Configuration();
FileSystem hdfs = FileSystem.get(URI.create(args[0]),conf);
FileStatus fs = hdfs.getFileStatus(new Path(args[0]));
System.out.println("path: "+fs.getPath());
System.out.println("length: "+fs.getLen());
System.out.println("modify time: "+fs.getModificationTime());
System.out.println("owner: "+fs.getOwner());
System.out.println("replication: "+fs.getReplication());
System.out.println("blockSize: "+fs.getBlockSize());
System.out.println("group: "+fs.getGroup());
System.out.println("permission: "+fs.getPermission().toString());
}
}
/** * @see 读取path下的所有文件 * @param path * @return * @throws IOException*/ public static String[] getFileList(String path) throws IOException{Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf); List<String> files = new ArrayList<String>(); Path s_path = new Path(path);if(fs.exists(s_path)){for(FileStatus status:fs.listStatus(s_path)){files.add(status.getPath().toString());}}fs.close();return files.toArray(new String[]{});}
- hadoop 文件目录操作
- 利用 Hadoop FileSystem listStatus 遍历文件目录 实现HDFS操作
- 利用 Hadoop FileSystem listStatus 遍历文件目录 实现HDFS操作
- hadoop文件操作命令
- Hadoop HDFS文件操作
- hadoop文件操作命令
- hadoop 一些文件操作
- Hadoop 文件操作
- 基本hadoop文件操作
- hadoop的文件操作
- Hadoop文件操作
- [小试牛刀] - Hadoop文件操作
- <hadoop>文件操作
- Hadoop文件操作
- perl 文件,目录操作
- 文件目录操作函数
- python文件目录操作
- 文件和目录操作
- 第7周、项目1—建立顺序环形队列算法库
- 项目2 -- 建立链栈算法库
- 第七周项目二建立链队算法库
- 第七周上机实践项目3——负数把正数赶出队列
- 第七周上机实践—项目3—负数把正数赶出队列
- hadoop 文件目录操作
- JAVA--reflect(反射)
- centos7上搭建docker私有仓库
- Eclipse 工程项目报错Target runtime com.genuitec.runtime.generic.jee60 is not defined
- 第四周项目4建设双链表算法库
- 第四周 建立双链表的算法库
- 第四周项目3—单链表应用(2)
- 第七周--负数把正数赶出队列
- 一点一滴掌握WPF应用系列 - 画刷使用(1):SolidColorBrush、LinearGradientBrush、RadialGradientBrush