This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Cant access file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Cant access file" Watch "Cant access file" New topic
Author

Cant access file

veena bijur
Ranch Hand

Joined: May 16, 2011
Posts: 67
Could you please tell what is the error?




output:


E:\JAVA_PROGRAMS\Files>javac B.java
B.java:11: error: cannot access File
File src = new File("E:/v.jpeg");
^
bad source file: .\File.java
file does not contain class File
Please remove or make sure it appears in the correct subdirectory of the sou
rcepath.
1 error

E:\JAVA_PROGRAMS\Files>





Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2332
    
  50
The Java source file name needs to be the same as the class name ie it should be called Demo.java
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3720
    
  16
Tony Docherty wrote:The Java source file name needs to be the same as the class name ie it should be called Demo.java

That's only true for public classes. It's not the problem here, although it is good practice to have classes in files with the same name.

@veena - have you got a file called File.java in the same directory as the B.java file ? If so, either delete it if you don't need it or rename it to have the same name as the class it contains.


Joanne
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2332
    
  50
Joanne Neal wrote:have you got a file called File.java in the same directory as the B.java file ?

Yes Joanne you are correct, I missed that reference to File. I guess I didn't read the full error message properly, thanks for correcting my reply.
veena bijur
Ranch Hand

Joined: May 16, 2011
Posts: 67
Thanks to both for the reply.

Yes, the directory consist of File.java, have removed it, now its working fine.

Thanks once again.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Cant access file