Netbeans - 读取 src 文件夹中的数据文件 [英] Netbeans - Reading a data file in src folder

查看:28
本文介绍了Netbeans - 读取 src 文件夹中的数据文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个扫描仪,它试图读取 src 文件夹中名为 info.data 的文件.我在线程main"中得到异常 java.io.FileNotFoundException: info.data(系统找不到指定的文件).我应该在扫描仪中输入的地址是什么?

I have a scanner that's trying to read a file named info.data in the src folder.I get Exception in thread "main" java.io.FileNotFoundException: info.data (The system cannot find the file specified). What's the address I should put in the scanner?

推荐答案

如果输入文件始终是您应用程序的一部分(即您稍后也将其放入 .jar 文件中),您应该使用 getResourceAsStream() 以读取其内容.

If the input file is always part of your application (i.e. you also put this into the .jar file later) you should use getResourceAsStream() in order to read its contents.

InputStream in = getClass().getResourceAsStream(filename);
Scanner scanner = new Scanner(in);

这篇关于Netbeans - 读取 src 文件夹中的数据文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆