程序如下:
import java.io.*;
class CustomerFile implements Serializable
{
String name;
int age;
public CustomerFile()
{
try
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("customer's name :");
name=br.readLine();
System.out.println("customer's age :");
age=Integer.parseInt(br.readLine());
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
class Customer
{
public static void main(String args[])
{
try
{
CustomerFile f=new CustomerFile();
FileOutputStream fos=new FileOutputStream("c:\\customer.txt");
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeObject(f);
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
我输入了Tom,30,写入customer.txt文件后,内容是乱码:
? sr CustomerFile蝯欉?s? I ageL namet Ljava/lang/String;xp t Tom
这个 程序要怎么修改才能解决这个问题?
[此贴子已经被作者于2006-4-17 20:00:46编辑过]