简体   繁体   English

从命令行使用StdIn接口时,Java在哪里寻找文件?

[英]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. 我忘记了Java在哪里寻找命令行文件。 For example if I am running the following from windows command line prompt: java -cp "C:\\Path\\To\\class\\" ClassName input.txt 例如,如果我从Windows命令行提示符运行以下命令:java -cp“ C:\\ Path \\ To \\ class \\” ClassName input.txt

Where does Java think I am asking it to look for input.txt? Java认为我在哪里要求它查找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. 到目前为止,如果文件在系统PATH或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. 注意:当您从程序内部使用扫描仪时,这与“ java在哪里寻找文件”问题不同。 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. 我遇到了“ NoClassDeffFound”错误,这与我的类路径有关。 My solution was to add a temporary class path location of the current directory by saying set classpath=%classpath%;.; 我的解决方案是通过说set classpath =%classpath%;。;添加当前目录的临时类路径位置。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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