Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cant access file

 
veena bijur
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2965
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java source file name needs to be the same as the class name ie it should be called Demo.java
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Tony Docherty
Bartender
Posts: 2965
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to both for the reply.

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

Thanks once again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic