aspose file tools*
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 Java 8 in Action this week in the Java 8 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: 1950
    
  28
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: 3169
    
  10
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: 1950
    
  28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cant access file
 
Similar Threads
Problem unzipping with ZipInputStream, containing filename with Swedish characters
Problem in copying JAR file
Exception
uncompressing .Z file in Unix
Problem in unzipping a folder using java.util.zip API