我正在編寫一個程序,該程序要求我編寫和讀回我創建的對象。當我試圖讀取對象並將其反序列化時,我得到一個表達式的錯誤開始。我想知道是否有人能告訴我這是一個怎樣解決的問題。從文件中讀取序列化對象
RandomAccessFile temp = new RandomAccessFile(fileSystemName,"r");
this.numberOfDirectories= temp.readInt();
this.fileSystemSize = temp.readInt();
this.numberOfBlocks = temp.readInt();
//Prepares and loads the bitMap
numberOfBytes = (numberOfBlocks/8)+1;
//directory = new Directory(numberOfDirectories);
bitMap = new byte[numberOfBytes];
for(int i=0;i<numberOfBytes;i++)bitMap[i]=temp.readByte();
temp.close();
FileInputStream fin = new FileInputStream(fileSystemName);
ObjectInputStream ois = new ObjectInputStream(fin);
//File file = new File(fileSystemName);
System.out.println(bitMap.length);
offset = 12 + numberOfBytes;
//ois.skipBytes(offset);
//Read Directories
directory = <Directory> ois.readObject();
該偏移是因爲我第一次使用RandomAccessFile對象先讀取一些整數和字符。我很感激幫助。謝謝
嘗試運行wihtout ois.skipBytes應用(偏移) – UVM 2012-04-16 05:50:58
請問你的代碼編譯?聽起來像是一個語法錯誤。也許你錯過了某個支架? – Kai 2012-04-16 05:51:44
您可以發佈堆棧跟蹤的一部分,以及寫入文件的代碼嗎?與這些特技通常與輸入 – 2012-04-16 05:53:33