java.io.StreamCorruptedException:无效的类型代码:9D

时间:2013-10-22 18:22:20

标签: java

我正在尝试在我的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();
    }
}
}

1 个答案:

答案 0 :(得分:0)

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

@EJP感谢你指出这一点。然后文件传输会混淆文件。