File file = new File ("temp.txt");
FileInputStream fin = new FileInputStream(file);
ObjectInputStream oin = new ObjectInputStream(fin);
不知道你说的 “同时将另一个对象加到这个流中“什么意思?
FileInputStream fin = new FileInputStream(file);
ObjectInputStream oin = new ObjectInputStream(fin);
不知道你说的 “同时将另一个对象加到这个流中“什么意思?
fin 和oin 都需要返回 一个 in
怎么做?
先都写到管道output,然后再把pipedInput返回
public InputStream getStream()
{
File file = new File ("temp.txt");
FileInputStream fin = new FileInputStream(file);
ObjectInputStream oin = new ObjectInputStream(fin);
String a = “new String”;
............. return (ObjectInputSteam)inputStream; //该输入流包含了oin和a的内容}
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); return new SequenceInputStream(ois, oin);
}
那可以
ObjectInputStream ois = new ObjectInputStream(new StringBufferInputStream(a));不知道行不行?
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;
}