首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请完成程序,首先由一个类simple实现Serializable接口,并有三个成员变量,分别为int型、double型和String型,可以用toString的方法显示这三个成员变量。在main方法中创建这个simple的持久对象,根据用户在命令行输入的三
请完成程序,首先由一个类simple实现Serializable接口,并有三个成员变量,分别为int型、double型和String型,可以用toString的方法显示这三个成员变量。在main方法中创建这个simple的持久对象,根据用户在命令行输入的三
admin
2009-12-22
38
问题
请完成程序,首先由一个类simple实现Serializable接口,并有三个成员变量,分别为int型、double型和String型,可以用toString的方法显示这三个成员变量。在main方法中创建这个simple的持久对象,根据用户在命令行输入的三个参数来设定其中成员变量的值。然后,将这个对象写入名为TheSerial.data的文件中,并显示成员变量。最后从文件TheSerial.data中读出三个成员变量并显示出来。
注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。
import java.io.*;
class TheSerial implements Serializable
{
private int intvalue;
private double doublevalue;
private String string;
The Serial ()
{
intvalue=123;
doublevalue=12.34;
string="Serialize Test";
}
public void setDouble(double d)
{
doublevalue=d;
}
public void setInt(int i)
{
intvalue=i;
}
public void setString(String s)
{
string=s;
}
public String to String()
{
return("int="+intvalue+" double="+doublevalue+" string="+string);
}
}
public class simple
{
public static void main(String[] args)
{
The Serial e1=new TheSerial();
TheSerial e2;
try
{
e1.setInt(Integer.parseInt(args[0]));
e1.setDouble(Double.parseDouble(args[1]));
e1.setString(args[2]);
}
catch(Exception e)
{
e1.setString(e.getMessage());
}
System.out.println(e1);
try
{
FileOutputStream oS=new FileOutputStream("TheSerial.data");
ObjectOutputStream oOS=new ObjectOutputStream(oS);
______;
}
catch(IOException ioException)
{
System.out.println (ioException.getMessage ());
}
try
{
FileInputStream iS=new FileInputStream("TheSerial.data");
ObjectInputStream oIS=new ObjectInputStream(iS);
______;
System.out.println(e2);
}
catch(IOException ioException)
{
System.out.println(ioException.getMessage());
}
catch(ClassNotFoundException cnfException)
{
System.out.println(cnfException.getMessage());
}
}
}
选项
答案
oOs.writeObject(e1) e2=(TheSerial)oIS.readObject()
解析
本题考查知识点:串行化要领和目的、串行化方法、基于文本的应用。解题思路:本题主要考查串行化相关的方法和实现。解题中首先要掌握串行化的基本过程和反串行化的过程。串行化过程首先要创建一个FileOutputStream,通过该类的实例对文件进行访问,然后创建一个ObjectOutputStream对象,通过writeObject()方法来实现对象的序列化。第1个空就是使用writeObject()实现序列化。反序列化过程中用FileInputStream对象建立读取文件的连接,并使用该对象创建一个ObjectInputSream实例的readObject()方法就可以实现对象的反序列化。第2个空就是使用readObject()实现反序列化。
转载请注明原文地址:https://kaotiyun.com/show/Scnp777K
本试题收录于:
二级Java题库NCRE全国计算机二级分类
0
二级Java
NCRE全国计算机二级
相关试题推荐
在VisualFoxPro中,下列关于SQL表定义语句(CREATETABLE)的说法中错误的是
下列程序段执行时在屏幕上显示的结果是x1=20X2=30SETUDFPARMSTOVALUEDOtestWITHx1.x2?x1.x2PROCEDUREtestPARAME
下列程序段执行以后,内存变量y的值是x=34567y==0DOWHILEx>0y=x%10+y*10x=int(x/10)ENDD
下列命令中,不会创建文件的是
根据“歌手”表建立视图myview,视图中含有“歌手号”左边第一位是“1”的所有记录,正确的SQL语句是
T面属于白盒测试方法的是
在一个空的表单中添加一个选项按钮组控件,该控件可能的默认名称是
(1)用SQL语句进行以下查询:查询“外汇账户”表中的日元信息。查询结果包括钞汇标志、金额,结果按金额降序排序,并存储于表two.dbf中,并将SQL语句存储于新建的three.txt文件中。(2)用一对多报表向导建立报表,“外汇代码”表为父表,“外汇账
以下关于关系的说法正确的是
随机试题
安徽省与江苏省、上海市、浙江省共同构成的长江三角洲城市群已成为国际六大世界级城市群之一。()
一般认为当人的各种器官达到成熟期后,会逐渐丧失其功能,这种现象就是老化。以下属于老年人生理老化的是()。
根据所给资料,回答下列问题。2014年5月,限额以上单位商品零售额同比增速最快的消费形态其2013年同期零售额比最慢的:
质量成本管理中,质量与成本以及质量成本诸要素之间客观上存在着内在逻辑关系。质量成本诸要素之间存在着此增彼降、各要素之间的互动关系。最佳质量成本水平是内外部损失成本曲线与预防鉴定成本曲线的交点。
锥体束病变,体征意义最大,也较易引出的是
天麻钩藤饮的组成药物中含有()
甲建筑工程公司与乙房地产开发公司签订承包合同,由甲建筑工程公司承建乙房地产开发公司开发的某住宅小区项目,工程竣工后乙房地产开发公司向甲建筑工程公司支付工程款600万元。甲建筑工程公司为了偿还向丙建筑材料公司购买建筑材料的货款,将承包合同获得600万元工程款
日本的化妆品,首推资生堂。近年来,它连续名列日本各化妆品公司榜首。资生堂之所以长盛不衰,与其独具特色的营销策略密不可分。20世纪80年代以前,资生堂实行的是一种不对顾客进行细分的大众营销策略,即希望自己的每种化妆品对所有的顾客都适用。80年代中期,资生堂因
在社会工作介入活动中,()是从“人与环境”互动的视角出发的,将介入焦点放在增强个人生活适应能力与增加社会和物理环境对个人需要的回应。
Itcanbeinferredfromthefirstparagraphthat______.Whatistheauthor’sattitudetowardsTheGrandPrairieAreaDemonstra
最新回复
(
0
)