private static String readPasswordFile(String masterPassFilePath) throws Exception
{
File masterPassFile = new File(masterPassFilePath);
if (!masterPassFile.exists())
{
throw new Exception("["+masterPassFilePath+"] does not exist");
}
}
,masterPassFile等于:
C:\temp\master.pass
返回true,if语句抛出错误。
我尝试了一堆不同的masterPassFilePath
值
C://temp//master.pass
C:/temp/master.pass
等等
其他信息master.pass是一个dat文件
我有点难过
编辑:
要回复许可,我可以访问它,我创建了它。
反斜杠转发速度问题。无论我尝试过什么
masterPassFile一直等于:
C:\temp\master.pass
现在为什么这会为
返回true !.exists()
答案 0 :(得分:1)
在现代Windows下,“ C:/temp/master.pass ”应该有效,如果您拥有该目录和文件的权限。使用反斜杠,需要在java源代码中转义它们:“ C:\\ temp \\ master.pass ”。尝试另一个文件(可能已锁定)。
答案 1 :(得分:0)
您是否遇到某种文件权限问题?这是否在上下文(例如tomcat)中运行,该上下文可能没有对目录或文件的读访问权。如果此代码在tomcat中运行,是否启用了安全模型以防止访问其他位置的文件?