public class helloworld implements Runnable
{ public int test = 3;
public int zz = 99;
public void setTest(int atest)
{
this.test = atest;
}
public static void main(String [] arg)
{
System.out.println("hello");
}
public void run()
{
System.out.println(" 运行开始"); }
}
/********************/
try{
helloworld p = new helloworld();
p.setTest(111);
System.out.println(p.test);
FileOutputStream os = new FileOutputStream("fileformat/cust.xml");
XMLEncoder encoder = new XMLEncoder(os);
encoder.writeObject(p);
encoder.close(); }
catch (Exception e)
{
}
/***********/
得到的cust.xml是这样子地
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2" class="java.beans.XMLDecoder">
<object class="fileformat.helloworld"/>
</java>
为什么没有test 和zz这两个成员变量一起添加进来呢?
public class helloworld implements Runnable,java.io.serialize
生成的xml文件还是上面的那个东东,大哥们帮帮忙啊public class helloworld implements Serializable
{
private static final long serialVersionUID = 616434644208950152L;
public int test = 3;
public int zz = 99;
public void setTest(int atest)
{
this.test = atest;
}
public int getNum()
{
return this.test;
}
public void set()
{
}
public helloworld()
{
}
public String toString()
{
return "";
} public static void main(String [] arg)
{
System.out.println("hello");
}
public void run()
{
System.out.println(" 运行开始"); }
}