这样清楚了?
public InputStream getStream()
{
File file = new File ("temp.txt");
FileInputStream fin = new FileInputStream(file);
ObjectInputStream oin = new ObjectInputStream(fin);
String a = “new String”;
.............
File file = new File ("temp.txt");
FileInputStream fin = new FileInputStream(file);
ObjectInputStream oin = new ObjectInputStream(fin);
不知道你说的 “同时将另一个对象加到这个流中“什么意思?
是有问题,这样就可以了:
public InputStream getStream()
{
File file = new File ("temp.txt");
FileInputStream fin = new FileInputStream(file);
ObjectInputStream oin = new ObjectInputStream(fin);
String a = “new String”;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(a);
try
{
while(true)
oos.writeObject(oin.readObject());
}
catch(EOFException e)
{
}
oos.flush();
oin.close();
ObjectInputStream result = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
return result;
}
是不是这样:
public InputStream getStream()
{
File file = new File ("temp.txt");
FileInputStream fin = new FileInputStream(file);
ObjectInputStream oin = new ObjectInputStream(fin);
String a = “new String”;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writObject(a);
byte[] objData = bos.toByteArray();
ByteArrayInputStream bis = new ByteArrayInputStream(objData);
ObjectInputStream ois = new ObjectIpuStream(bis);