读取文件的文件位置
我需要在属性文件中设置文件位置,以便稍后在类文件中使用它。例如我有,
anamelistfile = /rsrs/anamelist.txt
这是在上下文下直接在文件夹 config 中的文件 propss.properties 中设置的。与“rsrs”文件夹相同。
在我的类文件中,我需要获取此文件位置。我使用以下代码来获取它,并在 fileloc 对象中获取了所需的值。
fileloc=Props.getproperty(anamelistfile )
//result was fileloc="/rsrs/anamelist.txt"
我使用以下代码来读取该文件。但是,一旦创建了 File 对象,它将文件路径视为“\rsrs\anamelist.txt”,并且我收到文件未找到异常。
File listFile = new File(fileloc);
BufferedReader input = new BufferedReader(new FileReader(listFile));
错误信息 异常:堆栈跟踪:java.io.FileNotFoundException:\rsrs\anamelist.txt(系统找不到指定的路径)
有人可以帮助我解决我在这里犯的错误吗?另外,我的开发环境是 Windows,生产环境是 Unix,所以我需要能够在两者上工作的解决方案。提前致谢
I need to set a file location in a properties file to use it later in the class file. for example I have,
anamelistfile = /rsrs/anamelist.txt
This is set up in file propss.properties in the folder config directly under the context. same with "rsrs" folder.
In my class file I need to get this file location. I used follwing code to get it and I got the required value in fileloc object.
fileloc=Props.getproperty(anamelistfile )
//result was fileloc="/rsrs/anamelist.txt"
I used following code to read the file. But once the File object is created, it is treating the file path as "\rsrs\anamelist.txt" and I am getting a file not found exception.
File listFile = new File(fileloc);
BufferedReader input = new BufferedReader(new FileReader(listFile));
error message
Exception: Stack Trace for:java.io.FileNotFoundException: \rsrs\anamelist.txt (The system cannot find the path specified)
Can someone please help me with what mistake I am making here? Also my dev environment is windows and prod is on Unix, so I need the solution to work on both. Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试...
Try...