簡體   English   中英

存在文件時返回false

[英]file exists returns false when file exists

我有以下代碼:

public static void main(String[] args){
    System.out.println(System.getProperty("user.dir"));
    File file = new File("/stuff.txt");
    System.out.println(file.exists());
}

但是,當我運行它時,盡管文件存在, file.exists()返回false。 我檢查了System.getProperty("user.dir")查找正確的文件夾。 我想我把文件放在正確的位置:結構如下:

-- filetest
    |-- FileTest.class
    |-- FileTest.java
    `-- stuff.txt

您將忽略當前的user.dir並使用根文件夾/ 要解決此問題,請刪除/ 喜歡,

File file = new File("stuff.txt"); // <-- look for "stuff.txt" in the current folder

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM