我面临一些问题来修复正确的文件路径。无法找到正确的文件路径
我有一个配置文件,以下是在config.properties条目:
strMasterTestSuiteFilePath="D:\\KeywordDrivenFramework\\MasterTestSuiteFile.xls"
然后我试图为什么它要else块读取此属性为
Properties prop=new Properties();
prop.load("config.properties")
String strpath=prop.getProperty("strMasterTestSuiteFilePath")
Syso(strpath) //prints above path with single slash as D:\KeywordDrivenFramework\MasterTestSuiteFile.xls
//When i use the same var for File existance check it say not exists
File obj=new File(strpath)
if(obj.exists())
Syso("Exists....")
else
Syso("Does not exist....")
,甚至虽然文件存在路径? 如何克服它? 我试过 String str= strpath.replaceAll("\","\\")
//但我得到一些语法错误“String类型的方法replaceAll(String,String)不适用于参数(String)” 任何人都可以帮助我解决这个问题吗?
找到我正努力,我要去的地方错误的代码?
public void LoadMasterTestSuite()
{
String strGlobalConfigSettingFilePath=System.getProperty("user.dir")+"/src/GlobalConfigurationSettings.properties";
FileInputStream objFIS; //Variable to hold FileSystem Objet
File objFile; //Variable to hold File Object
try
{
objFIS = new FileInputStream(new File(strGlobalConfigSettingFilePath));
globalObjProp.load(objFIS);
strMasterTSFilePath=globalObjProp.getProperty("strMasterTestSuiteFilePath");
objAppLog.info("Master Test Suite File Path configured as "+strMasterTSFilePath);
}catch (FileNotFoundException e)
{
objAppLog.info("Unable to find Global Configuration Settings File. So aborting...");
e.printStackTrace();
}catch (IOException e)
{
e.printStackTrace();
}
String str=strMasterTSFilePath.replace("\\", "\\\\");
objFile=new File(str);
System.out.println(str);
if(objFile.exists())
{
LoadTestSuite(strMasterTSFilePath);
}
else
{
objAppLog.info("Master Test Suite File not found at Path: "+strMasterTSFilePath);
System.exit(-1);
}
}
'字符串str = strpath.replaceAll(“\”,“\\”)'将无法工作,因为你必须要能够创建'String'用反斜杠(你是不是)在第一个地方,然后替换他们。而一个愚蠢的问题,但文件确实存在? – Eypros
可能是,您使用的文件扩展名不正确。你能否检查一下你的文件是否是'MasterTestSuiteFile'扩展名'xls'?它可能是'xlsx'或其他东西。 – TDHM