#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    4
    Rep Power
    0

    The import java.nio.file.attribute.Attributes cannot be resolved


    Whenever I call this import statement:

    import java.nio.file.attribute.Attributes;

    I get this error message:

    The import java.nio.file.attribute.Attributes cannot be resolved.

    and I have no idea why. It's probably a dumb easy fix but I'm just a student stumbling around.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    Where have you seen that package/class referenced? Why do you think it is defined?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    4
    Rep Power
    0
    It's been used by several of the examples in my textbook. Also, I can't post URL's but if you google 'java.nio.file.attribute.Attributes' the first hit is a description of the class. So I should be able to import it, right?
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    You can import it if its defined. Look in the API doc for 1.7 and see if it's there.

    Post the link from google. The ones I found were for problems like yours.
    Last edited by NormR; April 7th, 2013 at 06:29 PM.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    4
    Rep Power
    0
    This site won't allow me to post links. When I google 'java.nio.file.attribute.Attributes' the first hit is titled 'Attributes (Java Platform SE 7 b124)' and it is a summary of the class. I don't know what you mean by API doc or where to find it.
  10. #6
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    The API doc:http://docs.oracle.com/javase/7/docs/api/

    Read some of the other sites google brings.

    Post the link with a space in it.
    Last edited by NormR; April 7th, 2013 at 08:10 PM.
  12. #7
  13. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,418
    Rep Power
    1713
    I don't know when your book was written but that is not a class in Java 7. It appears to have been part of the draft standard but didn't make it.

    Can you post some code that you're trying to run? I'm guessing that it is one of the other java.nio.file.attribute classes that you need.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    4
    Rep Power
    0
    h ttp://download.java.n et/jdk7/archive/b124/docs/api/java/nio/file/attribute/Attributes.htm l

    That's the page I found (with a few spaces) that summarizes the Attributes class, but you're right that it isn't in the API document, so... I don't know what the difference is.

    import java.nio.file.*;
    import java.nio.file.Path;
    import java.nio.file.attribute.*;
    import java.nio.file.attribute.Attributes;
    import java.io.IOException;

    public class FileStatistics
    {
    public static void main(String[] args)
    {
    Path filePath = Paths.get("C:\\Users\\Colin\\Desktop\\testfile.rtf");
    try
    {
    BasicFileAttributes attr = Attributes.readBasicFileAttributes(filePath);
    System.out.println("Creation time " + filePath.getFileName());
    System.out.println("Last modified time " + attr.lastModifiedTime());
    System.out.println("Size " + attr.size());
    }
    catch(IOException e)
    {
    System.out.println("IO Exception");
    }
    }

    }
  16. #9
  17. Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    May 2004
    Location
    Superior, CO, USA
    Posts
    2,418
    Rep Power
    1713
    Based on a more recent code sample I changed your code to:

    java Code:
    import java.nio.file.*;
    import java.nio.file.Path;
    import java.nio.file.attribute.*;
    import java.io.IOException;
     
    public class FileStatistics {
        public static void main(String[] args) {
            Path filePath = Paths.get("FileStatistics.java");
            try {
                PosixFileAttributeView view = (PosixFileAttributeView)Files.getFileAttributeView(filePath, PosixFileAttributeView.class);
                PosixFileAttributes attr = (PosixFileAttributes) view.readAttributes();
                System.out.println("Creation time " + filePath.getFileName());
                System.out.println("Last modified time " + attr.lastModifiedTime());
                System.out.println("Size " + attr.size());
            }
            catch(IOException e) {
                System.out.println("IO Exception");
            }
        }
    }


    The sample code you link to is also from the pre-release version so the interface must have changed during development.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    1
    Rep Power
    0

    Post Same Issue Using Java Programming by Joyce Farrell 6th Ed


    Hello,
    I am having the same issue and am using the book Java Programming, 6th Edition, by Joyce Farrell. It is chapter 13. So the "java.nio.file.attribute.Attributes" library is deprecated by not even making the final cut? Is it going to be in another release?
    Thank you.

IMN logo majestic logo threadwatch logo seochat tools logo