<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Is there anyway to get owner of a file hdfs via java ? in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-there-anyway-to-get-owner-of-a-file-hdfs-via-java/m-p/114246#M54897</link>
    <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/2273/saurabhmcakiet.html" nodeid="2273"&gt;@Saurabh&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You can try the following code:&lt;/P&gt;&lt;PRE&gt;import java.io.*;
import java.util.*;
import java.net.*;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;

public class FileStatusChecker {
    public static void main (String [] args) throws Exception {
        try{
            FileSystem fs = FileSystem.get(new Configuration());
            FileStatus[] status = fs.listStatus(new Path("hdfs://sandbox.hortonworks.com:8020/testing/ambari-server.log"));  // you need to pass in your hdfs path

            for (int i=0;i&amp;lt;status.length;i++){
                String path = status[i].getPath().toString();
                String owner = status[i].getOwner();
                System.out.println("\n\t PATH: " + path + "\t OWNER: " +owner);
            }
        } catch(Exception e){
            System.out.println("File not found");
            e.printStackTrace();
        }
    }
}&lt;/PRE&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;Here in the above code you can pass either a specific file &lt;/P&gt;&lt;PRE&gt;newPath("hdfs://sandbox.hortonworks.com:8020/testing/ambari-server.log")&lt;/PRE&gt;&lt;P&gt;Or a directory as well:&lt;/P&gt;&lt;PRE&gt;newPath("hdfs://sandbox.hortonworks.com:8020/testing")&lt;/PRE&gt;</description>
    <pubDate>Mon, 20 Feb 2017 18:44:29 GMT</pubDate>
    <dc:creator>jsensharma</dc:creator>
    <dc:date>2017-02-20T18:44:29Z</dc:date>
    <item>
      <title>Is there anyway to get owner of a file hdfs via java ?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-there-anyway-to-get-owner-of-a-file-hdfs-via-java/m-p/114245#M54896</link>
      <description>&lt;P&gt;Team,&lt;/P&gt;&lt;P&gt;I am trying to get owner of a hdfs file via java, can someone please guid me how to get owner of hdfs files.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2017 17:57:34 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-there-anyway-to-get-owner-of-a-file-hdfs-via-java/m-p/114245#M54896</guid>
      <dc:creator>SK1</dc:creator>
      <dc:date>2017-02-20T17:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: Is there anyway to get owner of a file hdfs via java ?</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-there-anyway-to-get-owner-of-a-file-hdfs-via-java/m-p/114246#M54897</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/2273/saurabhmcakiet.html" nodeid="2273"&gt;@Saurabh&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You can try the following code:&lt;/P&gt;&lt;PRE&gt;import java.io.*;
import java.util.*;
import java.net.*;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;

public class FileStatusChecker {
    public static void main (String [] args) throws Exception {
        try{
            FileSystem fs = FileSystem.get(new Configuration());
            FileStatus[] status = fs.listStatus(new Path("hdfs://sandbox.hortonworks.com:8020/testing/ambari-server.log"));  // you need to pass in your hdfs path

            for (int i=0;i&amp;lt;status.length;i++){
                String path = status[i].getPath().toString();
                String owner = status[i].getOwner();
                System.out.println("\n\t PATH: " + path + "\t OWNER: " +owner);
            }
        } catch(Exception e){
            System.out.println("File not found");
            e.printStackTrace();
        }
    }
}&lt;/PRE&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;Here in the above code you can pass either a specific file &lt;/P&gt;&lt;PRE&gt;newPath("hdfs://sandbox.hortonworks.com:8020/testing/ambari-server.log")&lt;/PRE&gt;&lt;P&gt;Or a directory as well:&lt;/P&gt;&lt;PRE&gt;newPath("hdfs://sandbox.hortonworks.com:8020/testing")&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Feb 2017 18:44:29 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Is-there-anyway-to-get-owner-of-a-file-hdfs-via-java/m-p/114246#M54897</guid>
      <dc:creator>jsensharma</dc:creator>
      <dc:date>2017-02-20T18:44:29Z</dc:date>
    </item>
  </channel>
</rss>

