Forums Register Login

Cant access file

+Pie Number of slices to send: Send
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>





+Pie Number of slices to send: Send
The Java source file name needs to be the same as the class name ie it should be called Demo.java
1
+Pie Number of slices to send: Send
 

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.

+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
Thanks to both for the reply.

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

Thanks once again.
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1146 times.
Similar Threads
Problem in copying JAR file
Exception
Problem unzipping with ZipInputStream, containing filename with Swedish characters
Problem in unzipping a folder using java.util.zip API
uncompressing .Z file in Unix
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 19:22:31.