Hadoop学习--设置配置文件参数列出目录结构--day04
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import org.junit.Test;
public class listfilestrcutor {
/**
* 列出文件目录结构
*/
@Test
public void listNum() throws Exception {
//创建configuration对象,有个默认的加载顺序,先从core-default.xml,再到src目录中的文件,这里
//我们给定了
Configuration conf = new Configuration();
//修改当前文件的副本数量
conf.set("dfs.replication", "4");
//修改当前文件的块大小
conf.set("dfs.blocksize", "20480");
FileSystem fs = FileSystem.get(conf);
//定义一个URL的字符串
String file = "hdfs://hadoop01:9000/user/hadoop";
//通过一个URL的字符串构建一个path对象
Path path = new Path(file);
FileStatus[] fst = fs.listStatus(path);
for(FileStatus fst0 : fst) {
System.out.println(fst0.getPath() + ": isFile() =" + fst0.isFile());
}
}
}