Untitled
unknown
plain_text
10 months ago
916 B
5
Indexable
Never
import java.io.FileInputStream; import java.io.IOException; public class SerializationFileValidator { public static void main(String[] args) { String filePath = "your_serialized_file.ser"; // 替换为你要验证的文件路径 try (FileInputStream fileInputStream = new FileInputStream(filePath)) { byte[] magicNumber = new byte[2]; if (fileInputStream.read(magicNumber) != 2) { System.out.println("文件太短,不是对象序列化文件。"); return; } if (magicNumber[0] == (byte) 0xAC && magicNumber[1] == (byte) 0xED) { System.out.println("这是一个Java对象序列化文件。"); } else { System.out.println("这不是一个Java对象序列化文件。"); } } catch (IOException e) { e.printStackTrace(); } } }