gpt4 book ai didi

java - Eclipse:带参数运行但未找到文本文件

转载 作者:行者123 更新时间:2023-12-01 18:38:42 24 4
gpt4 key购买 nike

我正在尝试运行 Algorithms (4th ed.) 中的程序

package binarysearch;
import edu.princeton.cs.introcs.*;
import java.util.Arrays;

public class BinarySearch {
public static int rank(int key, int[] a)
{
int lo = 0;
int hi = a.length - 1;
while (lo <= hi)
{
int mid = lo + (hi - lo) / 2;
if (key < a[mid]) hi = mid - 1;
else if (key > a[mid]) lo = mid + 1;
else return mid;
}
return -1;
}

public static void main(String[] args)
{
int[] whitelist = In.readInts(args[0]);

Arrays.sort(whitelist);

while(!StdIn.isEmpty())
{
int key = StdIn.readInt();
if (rank(key, whitelist) == -1)
StdOut.println(key);
}
}
}

运行程序的命令是

% java BinarySearch tinyW.txt < tinyT.txt

我将文本文件添加到我想要运行的包中。

enter image description here

我还添加了运行配置中所需的参数。

enter image description here

但是 Eclipse 告诉我这个错误消息。

enter image description here

我不知道为什么 Eclipse 无法打开该文件。我也手动将文件权限设置为777。有什么想法吗?

最佳答案

我认为您正在尝试重定向您的输入。请参阅此。

所以tinyW.txt是你的程序参数,没关系。
但tinyT.txt 不是,你只是想
将tinyT.txt 重定向到标准输入。

https://bugs.eclipse.org/bugs/show_bug.cgi?id=155411

似乎 Eclipse 不支持这个。

我只是尝试从 Eclipse 外部运行它。

另请参阅此。 Eclipse reading stdin (System.in) from a file

关于java - Eclipse:带参数运行但未找到文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20792835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com