This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Error: cannot find File Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error: cannot find File" Watch "Error: cannot find File" New topic
Author

Error: cannot find File

bra nbain
Greenhorn

Joined: Dec 26, 2008
Posts: 10
It's me, again. I have to be the person with the most problems in getting Java to work. I have set my path variable. It's corrcect because now javac works. But when I save a file -in this case I save a file: "MyFirstApp.java" in a file on my desktop. But when I run it on command prompt, I get an error saying

"Error: cannot read: MyFirstApp.java"

I'm doing on command prompt: javac MyFirstApp.java, whats wrong?

--Thanks so much for all of those people who helped me before and might
help here
[ January 02, 2009: Message edited by: bra nbain ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The Windows command prompt has a notion of a "current directory." If you type "dir" to see a listing of files, it'll be the files in the current directory that get listed. Depending on the version of Windows you're using the default current directory might be any number of things, but it'll pretty much never be your desktop folder.

You can change your current directory (not the default, which will be the same every time you start the command prompt; you change it just for the current session) using the "cd" command, as in

cd c:\Documents and Settings\nbain\Desktop

(where I used "nbain" for your Windows user name, since I don't know your real one.) If you issue that "cd" command correctly, you should find that your "javac" command will then work.

But the Desktop folder is a lousy place to put things. Generally you want to create a directory to keep your Java work in:

mkdir c:\java

and then store your work in that "c:\java" folder. When you want to compile and run your programs,

cd c:\java
javac Whatever.java
java Whatever


[Jess in Action][AskingGoodQuestions]
bra nbain
Greenhorn

Joined: Dec 26, 2008
Posts: 10
Thanks! Thanks! Thanks! I finnally got it to work! Thanks so much!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error: cannot find File
 
Similar Threads
Cannot run program from another directory other than c:\Sun\SDK\jdk\bin
Javac: File Not Found
New to Java
error message in terminal
Very simple program from Head First is showing no output on print