Search code examples
javacmderror-handlingfile-not-found

file not found: HelloWorld.java


I started to learn Java and the first task was do write a 'Hello World' Code. Saved it in documents and had to open it in cmd. thats what i type in:

cd documents
javac HelloWorld.java

my problem: I always get the error: file not found: HelloWorld.java

the class is definitely HelloWorld and its saved to as HelloWorld.java

but when I open this document the path says:

C:\Users\myusername\OneDrive\Documents\HelloWorld.java

hope you can understand my problem, thx for answers


Solution

  • Check if the java file is in your Documents folder, by writing:

    dir
    

    or for macos:

    ls
    

    But since you said it is in your OneDrive then you should navigate there with the cd command. (Use TAB to fill out the folder names and/or filenames for you automatically. To check directory just write cd without anything behind it in windows, or pwd for macos. When you've checked that the Java file is in your current directory you can just compile it normally with javac.