小编rob*_*uin的帖子

我应该在哪里放置文本文件以供 netbeans 读取?

我是java新手,但我一直在寻找答案,但不幸的是还没有找到适合我情况的答案。我想知道将我的文件“icecream.txt”放在哪里以便 netbeans 可以读取它。如果我编写绝对路径,我的程序就可以工作,但我不想这样做,因为它需要在其他学生的计算机上运行而无需更改。我附上了我放置文件的位置的图像。任何帮助,将不胜感激。 整洁的豆子文件夹

如果有帮助的话我的代码如下

package icecreamsales;
/**
 *
 * @author anonymous
 */
public class IceCreamSales {

/**
 * @param args the command line arguments
 */
    public static void main(String[] args) {

        try {
             TextIO.readFile("icecream.txt");
        }
        catch (IllegalArgumentException e) {
            System.out.println("Can't open file \"icecream.txt\" for reading!");
            System.out.println("Please make sure the file is present before");
            System.out.println("running the program.");
            System.exit(1);  // Terminates the program.
    }

        int totalIceCreamSales = 0;
        int strawberryIceCreamSales = 0;

        while (!TextIO.eof()) {
            String readLines = TextIO.getln();
            totalIceCreamSales++;

            if …
Run Code Online (Sandbox Code Playgroud)

java netbeans

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

netbeans ×1