我的項(xiàng)目結(jié)構(gòu):/myProject/ src/ main/... test/ resources/ myFile.txt當(dāng)我將文件放在主項(xiàng)目文件夾下時(shí):/myProject/ myFile.txt src/ main/... test/ resources/我的通話有效:String myFile = "myFile.txt";isFileThere(myFile);但是,當(dāng)我將文件放入資源文件夾并構(gòu)建其相對(duì)路徑時(shí),它不起作用:String myFile = "myFile.txt";String fullPath = String.format("/src/test/resources/%s", myFile);isFileThere(fullPath);***java.io.FileNotFoundException: \src\test\resources\myFile.txt (The system cannot find the path specified) at java.base/java.io.FileInputStream.open0(Native Method)
1 回答

波斯汪
TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超4個(gè)贊
從我的路徑中刪除前導(dǎo)的“/”將會(huì)有所幫助。我最初認(rèn)為沒有,因?yàn)槟抢餂]有文件。后來我添加了該文件,省略了前導(dǎo)“/”并得到了我的文件!
添加回答
舉報(bào)
0/150
提交
取消