Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Attributes errors

    In Java
    Create a file using any word processing program or text editor.

    Write an application that displays the file's name, containing

    folder size and time of last modification.
    Save as FileStatistics
    This is what I have with errors, what am I missing here ?
    Thanks
    <CODE>
    import java.nio.file.*;
    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:\\Java\\FileStatistics.txt");
    try
    {
    BasicFileAttributes attr =
    Attributes.readBasicFileAttributes(filePath);
    System.out.println("Creation time " + attr.creationTime());
    System.out.println("Last modified time " + attr.lastModifiedTime());
    System.out.println("Size " + attr.size());
    }
    catch(IOException e)
    {
    System.out.println("IO Exception");
    }
    }
    }
    <CODE>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    From what I can see on the java 7 api, the Attributes class does not have a method called readBasicFileAttributes. Files does though, but you will need to specify as well what class it is to be cast to:
    PHP Code:
    BasicFileAttributes attr Files.readBasicFileAttributes(filePathBasicFileAttributes.class); 

  • Users who have thanked Fou-Lu for this post:

    hillary (10-09-2011)

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    reply

    Hi FOU-lu.
    Thanks


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •