[英]java.io.FileNotFoundException: It is not able to locate my file?
[英]java.io.FileNotFoundException cannot locate file under src folder
我可以使用Scanner
打開文件(在Mac上的Eclipse Luna中運行時):
try {
input = new Scanner(new File("./src/A-small-practice.in"));
} catch (FileNotFoundException e){
System.out.println("ERROR: No File to read from");
}
...使用上面顯示的相對路徑。 但是,當我將其遷移到Windows 7上的Eclipse Neon時,它將引發FileNotFoundException
。 我試過src/
, ./src/
, ../src/
和/src/
,沒有一個似乎工作。 我該怎么辦?
臨時解決方案:
if(System.getProperty("os.name").toLowerCase().startsWith("mac os x")){
input = new Scanner(new File("./src/A-small-practice.in"));
}
else if (System.getProperty("os.name").toLowerCase().startsWith("wind")){
/* Absolute path */
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.