考虑这两个函数:
Function A
将 inputStream 作为参数。
public void processStream(InputStream stream)
{
//Do process routine
}
Function B
加载文件内容以将其传递给Function A
as InputStream
。
pulic void loadFile()
{
File file =new File("c:\\file.txt");
//Pass file as InputStream
}
如何在不直接读取文件的情况下将文件Function B
作为Function A
InputStream 传递?
我做了这样的事情:
File file = new File("c:\\file.txt");
DataInputStream stream= new DataInputStream(new FileInputStream(file));
这产生了以下异常:
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: java.io.DataInputStream
编辑:
loadFile()
正在将 InputStream 作为 RMI 响应传递。