0

I am doing the following:

How do I get the name of a file's owner in Java on OSX?

Here is my code:

private String getOwner(File f)
{
    Path p = Paths.get(f.getAbsolutePath());
    UserPrincipal owner = Files.getOwner(p);
    return owner.getName();
}

I get a "cannot find symbol" error. Here it is:

...$ javac Delete.java
Delete.java:38: error: cannot find symbol
    UserPrincipal owner = Files.getOwner(p);
    ^
  symbol:   class UserPrincipal
  location: class Delete
1 error

I know what the error means and I have tried several import statements:

java.security.*; (http://docs.oracle.com/javase/7/docs/api/)

java.nio.file.attribute; (http://docs.oracle.com/javase/7/docs/api/)

I feel ridiculous even having to ask this but I have no idea what I could be doing wrong!

Community
  • 1
  • 1
jacky
  • 195
  • 6
  • 17

1 Answers1

1

I was able to compile and run your code on my Mac with the following imports:

import java.nio.file.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.attribute.UserPrincipal;

and in the following format:

private String getOwner(File f) throws IOException {
    Path p = Paths.get(f.getAbsolutePath());
    UserPrincipal owner = Files.getOwner(p);
    return owner.getName();
}

You should check if you really use Java 7 in that place where you compile your code.

Artem Shafranov
  • 2,655
  • 19
  • 19
  • Ahh, ok. I will try those. I ran the javac -version in the same window in Terminal that I use to compile so I assume that's the same place! – jacky Sep 24 '12 at 00:43