Java序列化对象 C#反序列化的 问题。。。。。 RT请问 如何实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你确定?在C#里 显示 the input stream is not a valid binary format = =但我想还有别的办法的 两边的流格式根本不相同,所以没有办法使用ObjectOutputStream的你必须使用自己定义的格式才行。 也就是说 没办法通过tricks 使用他们提供的fomart而是要自己在两边实现一个de/serialization的process??只有这个办法? // java 版 public class SerObject { public static void main(String[] args) throws Exception { //序列 Student stu = new Student("张三", "男"); ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream( new File("student.ini"))); oos.writeObject(stu); //反序列 ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("student.ini"))); Student stu2 = (Student) ois.readObject() ; System.out.println(stu.getSname()); }} // c#版 //序列 static void BinarySerialize() { Student stu = new Student("胡锦涛","男"); //1.定义文件流 FileStream fs = new FileStream("E:\\stu.obj",FileMode.Create); //2.实例化序列化对象 BinaryFormatter bf = new BinaryFormatter(); //3.执行序列化 bf.Serialize(fs, stu); //4.关闭文件流 fs.Close(); } //反序列 static void BinaryDeserialize() { //1.定义文件流 FileStream fs = new FileStream("E:\\stu.obj", FileMode.Open,FileAccess.Read); //2.实例化序列化对象 BinaryFormatter bf = new BinaryFormatter(); //3.执行序列化 Student stu = (Student)bf.Deserialize(fs); //4.关闭文件流 fs.Close(); Console.WriteLine(stu.Name + "\t" + stu.Age); } 可能是我表述不清 楼上有些朋友误会我的意思我想在C#里反序列化被JAVA序列化的对象(抑或反之)但是由于平台不同,格式有差异。已经用wox实现了。现在在看wox的源代码,希望能自己写一个简单的 中间件 楼主现在实现了吗?我现在也要用C#反序列化被Java序列化的对象,求指导啊!!!感激不尽,这几天被这问题折磨死了! struts2中的下拉列表中listKey和listValue的问题 麻烦各位写个正则表达式 java 如何获取跨网段的计算机名? 为什么我一用spring声明式事务`再去获得这个带事务的bean的话就会得到一个代理类啊 谁有软件开发方面的经典电子书籍。。 webservices如何通过代码服务器通讯数据 急等!!! cookie的奇怪问题! 为什么Java Web工程只能定制化?即只能是项目,不能是产品? 批量删除时的javascript验证问题 JSP如何实现调用客户端的exe程序??在线等待!! 我们爱分享---Oracle效率小技巧 问个java导出word的问题
你确定?在C#里 显示 the input stream is not a valid binary format = =
但我想还有别的办法的
也就是说 没办法通过tricks 使用他们提供的fomart而是要自己在两边实现一个de/serialization的process??只有这个办法?
// java 版
public class SerObject {
public static void main(String[] args) throws Exception {
//序列
Student stu = new Student("张三", "男");
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(
new File("student.ini")));
oos.writeObject(stu);
//反序列
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("student.ini")));
Student stu2 = (Student) ois.readObject() ;
System.out.println(stu.getSname());
}} // c#版
//序列
static void BinarySerialize() {
Student stu = new Student("胡锦涛","男");
//1.定义文件流
FileStream fs = new FileStream("E:\\stu.obj",FileMode.Create);
//2.实例化序列化对象
BinaryFormatter bf = new BinaryFormatter();
//3.执行序列化
bf.Serialize(fs, stu);
//4.关闭文件流
fs.Close();
} //反序列
static void BinaryDeserialize() {
//1.定义文件流
FileStream fs = new FileStream("E:\\stu.obj", FileMode.Open,FileAccess.Read);
//2.实例化序列化对象
BinaryFormatter bf = new BinaryFormatter();
//3.执行序列化
Student stu = (Student)bf.Deserialize(fs);
//4.关闭文件流
fs.Close(); Console.WriteLine(stu.Name + "\t" + stu.Age); }
但是由于平台不同,格式有差异。已经用wox实现了。
现在在看wox的源代码,希望能自己写一个简单的 中间件