0

我想测试 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 文件,但我不确定这是否是问题所在。感谢所有愿意帮助我理解这个问题的人。

4

1 回答 1

0

看看这个:http ://www.cs.swarthmore.edu/~newhall/unixhelp/debuggingtips_Java.html

听起来您正在尝试使用 Java 编译器 (javac) 运行该程序。构建类文件后,您应该能够运行(从包含运行长度目录的目录)java runlength.RunLength -。那输出是什么?

另外,您使用什么工具来构建?如果它只是 javac 它不会说“构建成功”,它不会产生输出(除非出现问题)。

于 2014-04-06T10:03:23.933 回答