aspose file tools*
The moose likes Features new in Java 7 and the fly likes Possible issue with Java 7 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Features new in Java 7
Bookmark "Possible issue with Java 7" Watch "Possible issue with Java 7" New topic
Author

Possible issue with Java 7

John Starr
Greenhorn

Joined: Dec 01, 2011
Posts: 3
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
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

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

Joined: Dec 01, 2011
Posts: 3
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
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

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

Joined: Dec 01, 2011
Posts: 3
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?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19790
    
  20

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:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Possible issue with Java 7