What are the basic commands commonly used in HDFS
Editor to share with you what the basic HDFS commands are commonly used, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
One: check the last modification time of the HDFS file
Public class Test6GetLTime {/ * View the last modification time of the HDFS file * * / public static void main (String [] args) {try {Configuration conf = new Configuration (); URI uri = new URI ("hdfs://192.168.226.129:9000") FileSystem fs = FileSystem.get (uri, conf); Path dfs = new Path ("hdfs://192.168.226.129:9000/"); FileStatus fileStatus = fs.getFileStatus (dfs); long modificationTime = fileStatus.getModificationTime () System.out.println ("Modefication time is:" + modificationTime);} catch (IllegalArgumentException e) {e.printStackTrace ();} catch (URISyntaxException e) {e.printStackTrace ();} catch (IOException e) {e.printStackTrace () }}}
Second: find the location of a file in the HDFS cluster
Public class Test7FileLocation {/ * find the location of a file in the HDFS cluster * * / public static void main (String [] args) {try {Configuration conf = new Configuration (); URI uri = new URI ("hdfs://192.168.226.129:9000") FileSystem fs = FileSystem.get (uri, conf); Path dfs = new Path ("hdfs://192.168.226.129:9000/rootdir/ssh.txt"); FileStatus fileStatus = fs.getFileStatus (dfs); BlockLocation [] blkLocations = fs.getFileBlockLocations (fileStatus,0, fileStatus.getLen ()) Int blockLen = blkLocations.length; System.out.println ("blockLen of length:" + blockLen); for (int item0)