import java.io.ByteArrayOutputStream;java
import java.io.FileInputStream;apache
import java.io.FileOutputStream;ide
import java.io.InputStream;oop
import java.net.URL;spa
import org.apache.hadoop.conf.Configuration;.net
import org.apache.hadoop.fs.FSDataInputStream;xml
import org.apache.hadoop.fs.FSDataOutputStream;對象
import org.apache.hadoop.fs.FileStatus;hadoop
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());
}
}
}