0

我正在尝试在我的 Linux 服务器上运行一个 jar 文件。在我的 Windows 桌面上,我可以使用以下命令很好地执行 jar 文件:

java -Xss1000m -XX:-UseGCOverheadLimit -Xmx5048m -jar test.jar

但是,当我在我的 Linux 服务器上运行它时,我收到以下错误:

java.io.StreamCorruptedException: invalid type code: 9D
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1374)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
    at com.test.test.Main.main(Main.java:41)

我的代码是:

public class Main {
public static void main(String[] args) throws Exception {
    String fromTextFile = "";
    String path = "";

    if (!SystemUtils.IS_OS_WINDOWS)
        path = "/var/www/tomcat/fetch/";

    fromTextFile = path + "resources/ac_geonames_country_all.txt";

    AhoCorasick tree = new AhoCorasick();

    ObjectInputStream ois;
    try {
        ois = new ObjectInputStream(new FileInputStream(fromTextFile));
        tree = (AhoCorasick) ois.readObject();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
}
4

1 回答 1

0

我设法让它工作。我直接在 Linux 服务器上重新创建了这些文件。现在一切正常。在文件传输过程中出现问题。或者 Java 在 Linux 上以不同的方式序列化文件。我没有线索。

@EJP 感谢您指出这一点。然后文件传输弄乱了文件。

于 2013-10-22T20:56:46.817 回答