代码始终抛出StreamCorruptedException,但我找不到任何解决方案。 这段代码有什么问题?
InputStream fileIs = null;
ObjectInputStream objIs = null;
UploadFileResponse resError = new UploadFileResponse();
List<UploadFileResponse> strData = new ArrayList<UploadFileResponse>();
UploadFileRequest fileData = null;
try {
File file = new File("e:/BackupAndRestore/");
File[] fileList = file.listFiles();
if (((null != fileList)) && (fileList.length > 0)) {
for (File tempFile : fileList) {
UploadFileResponse res = new UploadFileResponse();
try {
fileIs = new FileInputStream(tempFile);
objIs = new ObjectInputStream(fileIs); //Line no 379
fileData = (UploadFileRequest) objIs.readObject();
res.setFileId(fileData.getFileId());
res.setFileName(fileData.getFileName());
res.setFilePath(fileData.getFilePath());
if (fileIds.equals(fileData.getFileId())) {
File uploadDir = new File(uploadDirectory + "/" + fileData.getFileName());
uploadDir.delete();
tempFile.delete();
strData.add(res);
}
} catch (Exception e) {
e.printStackTrace();
}
finally { if (objIs != null && fileIs!=null) objIs.close(); fileIs.close(); }
}
这是我的控制台:
java.io.StreamCorruptedException: invalid stream header: 00000020
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at com.example.demo.controller.FileController.deleteFileById(FileController.java:379)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at ...
提前谢谢。