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

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

问题描述

我有一个扫描程序正在尝试读取src文件夹中名为info.data的文件。我在线程main中得到Exception 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天全站免登陆