Java 文件(AbsolutePath)告诉我找不到文件

Java 文件(AbsolutePath)告诉我找不到文件,java,file,path,Java,File,Path,主密码文件等于: private static String readPasswordFile(String masterPassFilePath) throws Exception { File masterPassFile = new File(masterPassFilePath); if (!masterPassFile.exists()) { throw ne

主密码文件等于:

    private static String readPasswordFile(String masterPassFilePath) throws Exception
        {
            File masterPassFile = new File(masterPassFilePath);
            if (!masterPassFile.exists())
            {
                throw new Exception("["+masterPassFilePath+"] does not exist");
            }
}
C://temp//master.pass
C:/temp/master.pass
对于引发错误的if语句,返回true

我尝试了一系列不同的
masterPassFilePath

C:\temp\master.pass
等等

其他信息master.pass是一个dat文件

我有点不知所措

编辑:

要回复权限,是的,我可以访问它,我已经创建了它

反斜杠正斜杠问题。不管我怎么努力

masterPassFile始终等于:

    private static String readPasswordFile(String masterPassFilePath) throws Exception
        {
            File masterPassFile = new File(masterPassFilePath);
            if (!masterPassFile.exists())
            {
                throw new Exception("["+masterPassFilePath+"] does not exist");
            }
}
C://temp//master.pass
C:/temp/master.pass
现在,为什么这会成为现实


!。exists()

是否遇到某种文件权限问题?这是在可能没有目录或文件读取权限的上下文(例如tomcat)中运行的。如果此代码在tomcat中运行,是否打开了安全模型以防止访问其他地方的文件?

在现代Windows下,如果您有目录和文件的权限,则“C:/temp/master.pass”应该可以工作。使用反斜杠时,需要在java源代码中转义它们:“C:\\temp\\master.pass”。尝试另一个文件(可能已锁定)。

尝试
C:\\temp\\master.pass
\\是\.的转义字符。文件是否确实存在?文件确实存在:)我已经移动了几次,看看这是否是一个问题@Marnix是的,对不起,我也尝试过,这就是etc的意思。另外,我正在Eclipse中以args的形式传递它们,所以它会处理转义字符,但我尝试使用它来加倍确定路径字符串的“@”使windows自动使用正确的“/”、“\”或其他字符。只需使用:@“C:\temp\master.pass”以确保这不是问题所在(如果您确定您的文件在那里:P)