串行化的问题

fk1998 2003-08-30 09:23:32
谁能解释一下串行化?具体应用?举个例子?
...全文
53 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
star821116 2003-08-30
  • 打赏
  • 举报
回复
就是把类以字节流的形式写入到磁盘或者IO设备,下面是一个例子,很简单的:
import java.io.*;
import java.util.*;

/** Demonstrate use of Serialization. */
public class SerialDemo {
protected static final String FILENAME = "serial.dat";

public static void main(String[] s) throws IOException {
new SerialDemo().save();
new SerialDemo().dump();
}

/** The save method in an appliction */
public void save() throws IOException {
ArrayList v = new ArrayList();
// Gather the data
MyData u1 = new MyData("Ian Darwin", "secret_java_cook");
v.add(new Date());
v.add(u1);
v.add(new MyData("Abby Brant", "dujordian"));
write(v);
}

/** Does the actual serialization */
public void write(Object theGraph) throws IOException {
// Save the data to disk.
ObjectOutputStream os = new ObjectOutputStream(
new BufferedOutputStream(
new FileOutputStream(FILENAME)));
os.writeObject(theGraph);
os.close();
}

public void dump() throws IOException {
ObjectInputStream is = new ObjectInputStream(
new FileInputStream(FILENAME));
System.out.println(is.readObject());
is.close();
}
}

/** Simple data class to be serialized. */
class MyData implements Serializable {
String userName;
String passwordCypher;
transient String passwordClear;
public MyData(String name, String clear) {
userName = name;
// Save the clear text p/w in the object, it won't get serialized
passwordClear = clear;
// So we must save the encryption! Encryption not shown here.
passwordCypher = DES.encrypt(passwordClear);
}
}

/** More of the demo; this just generates a String; Strings are serializable */
class DES {
// Obviously just a placeholder.
public static String encrypt(String s) {
return s;
}
}
C#串口介绍以及简单串口通信程序设计实现 源代码和串口程序介绍连接:https://www.cnblogs.com/JiYF/p/6618696.html 本站积分太贵,自己变得。。直接到连接地址下载代码 周末,没事干,写个简单的串口通信工具,也算是本周末曾来过,废话不多,直接到主题 串口介绍   串行接口简称串口,也称串行通信接口或串行通讯接口(通常指COM接口),是采用串行通信方式的扩展接口。(至于再详细,自己百度) 串口应用:   工业领域使用较多,比如:数据采集,设备控制等等,好多都是用串口通信来实现!你要是细心的话,你会发现,目前家用国网智能电能表就具备RS485通信总线(串行总线的一种)与RS232可以相互转化(当然一般,非专业的谁也不会闲的蛋疼,趴电表上瞎看,最多也就看看走了多少度电) RS232 DB9介绍: 1.示意图 2.针脚介绍: 载波检测(DCD) 接受数据(RXD) 发出数据(TXD) 数据终端准备好(DTR) 信号地线(SG) 数据准备好(DSR) 请求发送(RTS) 清除发送(CTS) 振铃指示(RI) 3.实物图: 以下是我购买XX公司的一个usb转串口线:这个头就是一个公头,另一端是一个usb口 笨小孩串口工具运行图: 1.开启程序 2.发送一行字符串HelloBenXH,直接将针脚的发送和接收链接起来就可以测试了(针脚2 接受数据(RXD) 和3 发出数据(TXD))直接链接, C#代码实现:采用SerialPort 1.实例化一个SerialPort [csharp] view plain copy 在CODE上查看代码片派生到我的代码片 private SerialPort ComDevice = new SerialPort(); 2.初始化参数绑定接收数据事件 [csharp] view plain copy 在CODE上查看代码片派生到我的代码片 public void init() { btnSend.Enabled = false; cbbComList.Items.AddRange(SerialPort.GetPortNames()); if (cbbComList.Items.Count > 0) { cbbComList.SelectedIndex = 0; } cbbBaudRate.SelectedIndex = 5; cbbDataBits.SelectedIndex = 0; cbbParity.SelectedIndex = 0; cbbStopBits.SelectedIndex = 0; pictureBox1.BackgroundImage = Properties.Resources.red; ComDevice.DataReceived += new SerialDataReceivedEventHandler(Com_DataReceived);//绑定事件 }

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧