Topic: 菜鸟求助!!一个Serializable的问题!

  Print this page

1.菜鸟求助!!一个Serializable的问题! Copy to clipboard
Posted by: sunxiaoming
Posted on: 2006-09-01 17:58

小弟初学JAVA 遇到点问题不知道怎么产生的这个个问题
代码如下:

import java.io.Serializable;
class Student implements Serializable
{
int id;
String name;
int age;
public Student(int id,String name,int age)
{
this.id=id;
this.name=name;
this.age=age;
}
}
public class Seriazlization
{
public static void main(String[] args) throws Exception
{
Student stu1 = new Student(19,"zhangsan",25);
Student stu2 = new Student(20,"lisi",24);
FileOutputStream fos = new FileOutputStream("student.txt");
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(stu1);
os.writeObject(stu2);
os.close();

FileIntputStream fis = new FileIntputStream();
ObjectIntputStream ois = new ObjectOutputStream(fis);
stu1 =(Student)ois.readObject();
stu2 =(Student)ois.readObject();
ois.close();

System.out.println("id" + stu1.id);
System.out.println("name" + name.id);
System.out.println("age" + age.id);

System.out.println("id" + stu2.id);
System.out.println("name" + stu2.name);
System.out.println("age" + stu2.age);

}
}

错误:
D:\学习环境\bin>javac Serialization.java
error: cannot read: Serialization.java
1 error

2.Re:菜鸟求助!!一个Serializable的问题! [Re: sunxiaoming] Copy to clipboard
Posted by: why
Posted on: 2006-09-01 18:42

check whether there is Serialization.java in your D:\学习环境\bin
perhaps you just have Serialization.java.txt

3.Re:菜鸟求助!!一个Serializable的问题! [Re: sunxiaoming] Copy to clipboard
Posted by: sunxiaoming
Posted on: 2006-09-01 22:41

前辈所说的我知道!但 我没有隐藏扩展名啊!

4.Re:菜鸟求助!!一个Serializable的问题! [Re: sunxiaoming] Copy to clipboard
Posted by: why
Posted on: 2006-09-02 07:30

Dead
public class Seriazlization
Serialization.java

5.Re:菜鸟求助!!一个Serializable的问题! [Re: sunxiaoming] Copy to clipboard
Posted by: sunxiaoming
Posted on: 2006-09-02 08:07

哦!!
不好意思 上面的一行代码有点错误 ,我贴上的是 修改以前的
System.out.println("id" + stu1.id);
System.out.println("name" + stu1.name);
System.out.println("age" + stu1.age);
**********************************************************
这次找到Serialization.java 了可是又有了错误!
D:\学习环境\bin>javac Serialization.java
Serialization.java:28: cannot resolve symbol
symbol : class FileIntputStream
location: class Serialization
FileIntputStream fis = new FileIntputStream();
^
Serialization.java:28: cannot resolve symbol
symbol : class FileIntputStream
location: class Serialization
FileIntputStream fis = new FileIntputStream();
^
Serialization.java:29: cannot resolve symbol
symbol : class ObjectIntputStream
location: class Serialization
ObjectIntputStream ois = new ObjectOutputStream(fis);
^
3 errors
类似这样的错误是因为 没有引入import java .io么? 我上面的程序已经 引入了啊!
您能介绍一本关于 产生编译错误的书么? 我在调程序的时候有很多错误不知道是怎么产生的!!!

6.Re:菜鸟求助!!一个Serializable的问题! [Re: sunxiaoming] Copy to clipboard
Posted by: why
Posted on: 2006-09-02 10:49

> 没有引入import java .io么? 我上面的程序已经 引入了啊!
Dead You only had
import java.io.Serializable;

7.Re:菜鸟求助!!一个Serializable的问题! [Re: sunxiaoming] Copy to clipboard
Posted by: sunxiaoming
Posted on: 2006-09-02 16:14

哦,呵呵 弄好 !! 谢谢啦!!!

8.Re:菜鸟求助!!一个Serializable的问题! [Re: sunxiaoming] Copy to clipboard
Posted by: sunxiaoming
Posted on: 2006-09-02 16:36

symbol : constructor FileInputStream ()
location: class java.io.FileInputStream
FileInputStream fis = new FileInputStream();
^
还要麻烦一下您,这样的错误 是什么啊?我第一次遇到
symbol : constructor FileInputStream ()

9.Re:菜鸟求助!!一个Serializable的问题! [Re: sunxiaoming] Copy to clipboard
Posted by: why
Posted on: 2006-09-02 17:03

http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileInputStream.html
FileInputStream does not have a default constructor but only
FileInputStream(File file)
Creates a FileInputStream by opening a connection to an actual file, the file named by the File object file in the file system.
FileInputStream(FileDescriptor fdObj)
Creates a FileInputStream by using the file descriptor fdObj, which represents an existing connection to an actual file in the file system.
FileInputStream(String name)
Creates a FileInputStream by opening a connection to an actual file, the file named by the path name name in the file system.

10.Re:菜鸟求助!!一个Serializable的问题! [Re: sunxiaoming] Copy to clipboard
Posted by: sunxiaoming
Posted on: 2006-09-04 13:56

哦,这次都弄明白了!!!谢谢!!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923