简体   繁体   中英

Where does Java look for files when using StdIn interface from Command Line?

I'm having a small embarrassing issue. I'm forgetting where Java looks for command-line files. For example if I am running the following from windows command line prompt: java -cp "C:\\Path\\To\\class\\" ClassName input.txt

Where does Java think I am asking it to look for input.txt? As of right now it doesn't seem to find the file if the file is anywhere in the system's PATH, or the java CLASS PATH.

This is a really stupid issue and I've spent over an hour on it and I can't seem to come to a conclusion. The worst part was that I've resolved this issue before but am having a bad day trying to remember how.

NOTE: This is not the same as the question "Where does java look for a file" when you are using a scanner from inside the program. This is specific to the method that looks like

public class Classname {
    public static void main(String args[])
    {
        In in = new In(args[0]);
        ...
    }
}

EDIT: Hi, I resolved the problem. I was a getting a "NoClassDeffFound" error and it had to do with my Class path. My solution was to add a temporary class path location of the current directory by saying set classpath=%classpath%;.;

类似于几乎所有东西都使用路径一样,如果它是相对路径,则基于您当前的工作目录。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM