Intellij Idea问题与文本文件无法读取 [英] Intellij Idea problem with text file impossible to read
问题描述
使用Intellij Idea时遇到问题。
I have a problem using Intellij Idea.
我绝对无法将文本文件作为InputStream加载 - 无论我把文件放在哪里(main / java,main / resources ...)它都无关紧要找不到文件 - 在Eclipse中一切正常。
I am absolutely unable to load text file as InputStream - it doesnt matter where do I put the file (main/java, main/resources...) it just can't find the file - in Eclipse everything works just fine.
我尝试了setings-> compiler->资源模式并添加了?*。txt但似乎没有工作要么。
I tried setings->compiler->resource patterns and added ?*.txt but that doesn't seem to work either.
感谢任何帮助。
推荐答案
如果您将其加载为a 文件
,确保在IDEA 运行/调试配置中正确设置工作目录,因为它是默认目录当您尝试访问文件时,Java将查找文件,如 new File(file.txt)
。工作目录应该设置为包含.txt文件的项目目录。
If you load it as a File
, make sure that Working Directory is properly set in IDEA Run/Debug Configuration, since it's the default directory where Java will look for a file when you try to access it like new File("file.txt")
. Working directory should be set to the directory of your project containing .txt files.
如果您将文件作为类路径资源加载,那么它们应该位于源下的某个位置 root并将根据设置
|复制到类路径编译器
| 资源模式
。
If you load files as a classpath resource, then they should reside somewhere under Source root and will be copied to the classpath according to Settings
| Compiler
| Resource Patterns
.
如果无法使其工作,请将项目上传到包括IDEA项目文件在内的某个位置,以便我们可以指出你的错误。
If you can't get it working, upload your project somewhere including IDEA project files so that we can point to your mistake.
这篇关于Intellij Idea问题与文本文件无法读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!