I have a swing application that accesses a text file via a BufferedReader. When I run it in NetBeans, the file is accessed fine. But, when I run the jar file itself from the command line, I get a FileNotFoundException.
I am using a FileInputStream, and initializing it with a path to the text file: FileInputStream fstream = new FileInputStream("appsDB/Apps.txt");
The appsDB folder is at the same level as the src folder, and so I'm guessing that's why the path works and the text file is found when I run it in NetBeans. What do I need to do differently, should I be specifying the path to the Apps.txt file differently?
尝试从包含appsDB目录的目录中运行jar
Yes, your assumption is correct. If possible, add the file to your src/somefolder folder and access it using getClass().getResourceAsStream("/somefolder/somefile")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.