且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

创建FileInputStream时出现java.io.FileNotFoundException

更新时间:2023-11-26 11:50:46

你提供文件的相对路径。这意味着程序将查找相​​对于工作目录的文件。

You provide a relative path for the file. That means program will look for the file relative to the working directory.

根据您运行程序的方式,它将是您运行它的目录(如果从Shell运行) / Cmd)或项目设置中配置的任何内容(如果从IDE运行)。对于后者,它取决于IDE,但通常是项目根目录。

Depending on how you run the program it will be the directory you run it from (if run from Shell/Cmd) or whatever is configured in the project settings (if run from the IDE). For the latter, it depends on the IDE but usually it's the project root directory.

有关工作目录的更多信息: https://en.wikipedia.org/wiki/Working_directory

关于相对路径的更多信息: https://en.wikipedia.org/wiki/Path_(computing)#Absolute_and_relative_paths

More info on working directory: https://en.wikipedia.org/wiki/Working_directory
More info on relative path: https://en.wikipedia.org/wiki/Path_(computing)#Absolute_and_relative_paths

关于文件的创建,如果要写入文件,它将创建不存在的文件。当你阅读它时,它期望它存在。这意味着您必须在阅读之前创建空文件(如果不存在)或将异常视为空内容

Regarding creation of the file, it would create non-existing file if you were to write to it. When you read it, it expects it to exist. That means you have to create empty file (if one does not exist) before reading or simply treat exception as empty content.