• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Possible issue with Java 7

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on this tutorial and having a few issues. Here is the problem "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 file as FileStatistics.java"

Here is what I have:



And this is the errors that I receive when I try to compile it: (I am using jGRASP)

----jGRASP exec: javac -g FileStatistics.java

FileStatistics.java:3: error: cannot find symbol
import java.nio.file.attribute.Attributes;
^
symbol: class Attributes
location: package java.nio.file.attribute
FileStatistics.java:15: error: method getName in interface Path cannot be applied to given types;
System.out.println("File name is " + file.getName());
^
required: int
found: no arguments
reason: actual and formal argument lists differ in length
FileStatistics.java:18: error: cannot find symbol
Attributes.readBasicFileAttributes(file);
^
symbol: variable Attributes
location: class FileStatistics
3 errors

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

I think I may be getting errors because of some compatibility issues with Java 7. Is there anything you can see that might be causing it?

Thanks,

-John


Sana: Added code tags
 
Sheriff
Posts: 28328
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, as far as I can see the errors are all yours.

The compiler is correct to say there is no "java.nio.file.attribute.Attributes" type. It's correct to say that the getName() method of Path requires an int parameter. At least based on my reading of the API documentation for Java 7, that's the case. Is there some reason you disagreed with those error messages?
 
John Starr
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Paul, the thing I was wondering about was this error:

BasicFileAttributes attr =
Attributes.readBasicFileAttributes(file);

I read the other topic post by Sverre Moe that talked about the Java 7 Confusion and here is what was said.


According to many different tutorials there are some differences to the official JDK7.

Interface FileRef is not in JDK7
References to path.copyTo, but method does not exist. Must instead use Files.copy
References to a class called Attributes, but does not exist. BasicFileAttributes basic = Attributes.readBasicFileAttributes. Must instead use Files.getFileAttributeView.


Would I have to replace

BasicFileAttributes attr =
Attributes.readBasicFileAttributes(file);

with Files.getFileAttributeView? Sorry, I am a noob at this. I think I fixed the other 2 errors I had.
 
Paul Clapham
Sheriff
Posts: 28328
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry, I haven't used those features in Java 7, all I did was to look in the API docs. I assume you must be working from an old example which was written back when Java 7 was still being designed? In that case I would suggest looking for a new tutorial. Like this one which I just googled up with keywords "java file tutorial". Looks like it's been updated to cover Java 7.
 
John Starr
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have another question for you, also let me know if I am posting these things in the wrong thread for this forum. I have this code here:

I want to change the file name to FileStatistics but when I change the public class to FileStatistics I get this error code:

FileStatistics.java:16: error: cannot find symbol
filename=in.nextLine();
^
symbol: variable in
location: class FileStatistics
1 error

What do I have to do to change the File name where I won't get error codes when I compile?
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no class java.nio.file.attribute.Attributes. If you check the Javadoc of BasicFileAttributes you see that the way to get these is using java.nio.file.Files:
 
Rob Spoor
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Starr wrote:What do I have to do to change the File name where I won't get error codes when I compile?


What should in be? I'm guession you forgot this line:
 
It's just like a fortune cookie, but instead of a cookie, it's pie. And we'll call it ... tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic