我想测试 Windows 可执行文件 (.exe) 上的运行长度编码算法,但运行程序时没有收到输出。没有编译错误;运行仅表明构建成功,仅此而已。
这是代码:
package runlength;
import edu.princeton.cs.introcs.BinaryStdIn;
import edu.princeton.cs.introcs.BinaryStdOut;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
public class RunLength {
private static final int R = 256;
private static final int lgR = 8;
public static void expand() {
boolean b = false;
while (!BinaryStdIn.isEmpty()) {
int run = BinaryStdIn.readInt(lgR);
for (int i = 0; i < run; i++)
BinaryStdOut.write(b);
b = !b;
}
BinaryStdOut.close();
}
public static void compress() {
char run = 0;
boolean old = false;
while (!BinaryStdIn.isEmpty()) {
boolean b = BinaryStdIn.readBoolean();
if (b != old) {
BinaryStdOut.write(run, lgR);
run = 1;
old = !old;
}
else {
if (run == R-1) {
BinaryStdOut.write(run, lgR);
run = 0;
BinaryStdOut.write(run, lgR);
}
run++;
}
}
BinaryStdOut.write(run, lgR);
BinaryStdOut.close();
}
public static void main(String[] args) throws FileNotFoundException {
BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\Owner\\Downloads\\adobe shockwave player setup.exe"));
if (args.length > 0)
{
switch (args[0]) {
case "-":
compress();
break;
case "+":
expand();
break;
default:
throw new IllegalArgumentException("Illegal command line argument");
}
}
}
}
我不相信我在主函数中正确传递了 .exe 文件,但我不确定这是否是问题所在。感谢所有愿意帮助我理解这个问题的人。