HDFS-windows下测试hdfs命令
生活随笔
收集整理的這篇文章主要介紹了
HDFS-windows下测试hdfs命令
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
public class HdfsClient1 {private FileSystem fs;//初始化一個FileSystem@Beforepublic void init() throws URISyntaxException, IOException, InterruptedException {//1:獲取文件系統URI uri = new URI("hdfs://myhadoop105:9820");Configuration conf = new Configuration();conf.set("dfs.replication","6");String user = "atguigu";fs = FileSystem.get(uri, conf, user);}@Afterpublic void closeResources() throws IOException {//3:關閉資源fs.close();}@Testpublic void testMkdir() throws IOException {fs.mkdirs(new Path("/hdfs/windowsOperator/operator01"));}@Testpublic void testPut() throws IOException {fs.copyFromLocalFile(false , false , new Path("G:/code/test/day08課堂記錄.txt") , new Path("/hdfs/windowsOperator/operator01"));}@Testpublic void testGet() throws IOException {fs.copyToLocalFile(new Path("/hdfs/windowsOperator/operator01"),new Path("G:\\code\\test\\test"));}@Testpublic void testMove() throws IOException {fs.rename(new Path("/hdfs/windowsOperator/day08課堂記錄.txt"),new Path("/hdfs/windowsOperator/day08"));}@Testpublic void testDelete() throws IOException {fs.delete(new Path("/hdfs/windowsOperator/operator01"),true);}@Testpublic void testIsFile() throws IOException {FileStatus[] fileStatuses = fs.listStatus(new Path("/"));for (FileStatus fileStatus : fileStatuses) {//判斷是否是文件if (fileStatus.isFile()){System.out.println("-:"+fileStatus.getPath().getName());}else {System.out.println("d:" + fileStatus.getPath().getName());}}}@Testpublic void testListFiles() throws IOException {// f:要查看的目錄路徑// r:是否遞歸查看RemoteIterator<LocatedFileStatus> listFiles = fs.listFiles(new Path("/"), true);while (listFiles.hasNext()){LocatedFileStatus fileStatus = listFiles.next();System.out.println("-------------------------" + fileStatus.getPath() + "--------------------");System.out.println(fileStatus.getPermission());System.out.println(fileStatus.getOwner());System.out.println(fileStatus.getGroup());System.out.println(fileStatus.getLen());System.out.println(fileStatus.getModificationTime());System.out.println(fileStatus.getReplication());System.out.println(fileStatus.getBlockLocations());System.out.println(fileStatus.getPath().getName());//快信息BlockLocation[] blockLocations = fileStatus.getBlockLocations();System.out.println(Arrays.toString(blockLocations));}}}
總結
以上是生活随笔為你收集整理的HDFS-windows下测试hdfs命令的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 转:Node.js和testacular
- 下一篇: 推理集 —— 实证