[英]How to specify path to file in Java?
您的abc
文件夾位於src
下,並且您正在使用帶有前導/
的絕對路徑,它在文件系統的根目錄中聲明它。
將文件夾移動到項目的根文件夾,然后引用為
File file = new File("abc/file.txt");
假設在 linux 你有這個文件在正確的路徑:例如。 /path/to/file/filename.txt
你可以試試這個:
對於 windows:
File file = new File("\\path\\to\\file\\filename.txt");
對於 Linux:
File file = new File("/path/to/file/filename.txt");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.