Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么InputStream实例在ObservableMap中引用时关闭?_Java_Inputstream - Fatal编程技术网

Java 为什么InputStream实例在ObservableMap中引用时关闭?

Java 为什么InputStream实例在ObservableMap中引用时关闭?,java,inputstream,Java,Inputstream,我有一个添加了资源文件的地图 private ObservableMap<String, InputStream> resourceFilesData; resourceFilesData = new ObservableMapWrapper<String, InputStream>( new HashMap<String, InputStream>() ); 最后,当我想使用流时,它们看起来是关闭的 为什么??我找不到理由。 也许,当小溪关闭的时候

我有一个添加了资源文件的地图

private ObservableMap<String, InputStream> resourceFilesData;
resourceFilesData = new ObservableMapWrapper<String, InputStream>(
    new HashMap<String, InputStream>()
);
最后,当我想使用流时,它们看起来是关闭的

为什么??我找不到理由。 也许,当小溪关闭的时候,有一些乳清需要处理吗?(用于调试)

如何使用流:

private void pack() throws JAXBException, IOException {
    HashMap<String, InputStream> resources = new HashMap<>();
    byte[] buf = new byte[1024];
    ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("../" + fwData.getFileName() + ".iolfw"));
    File xml = fwData.marshal();
    InputStream xmlStream = new FileInputStream(xml);

    resources.put(xml.getName(), xmlStream);
    resources.putAll(resourceFilesData);
    for (Map.Entry<String, InputStream> data: resources.entrySet()) {
        InputStream input = data.getValue();
        zos.putNextEntry(new ZipEntry(data.getKey()));

        for (int readNum = 0; (readNum = input.read(buf)) != -1; ) {
            zos.write(buf, 0, readNum);
        }
        zos.closeEntry();
        input.close();
    }
    zos.close();
    resources.remove(xmlStream);
    xml.delete();
}
private void pack()抛出jaxbeexception,IOException{
HashMap resources=newhashmap();
字节[]buf=新字节[1024];
ZipOutputStream zos=new-zipoutpstream(new-FileOutputStream(“../”+fwData.getFileName()+“.iolfw”);
文件xml=fwData.marshal();
InputStream xmlStream=新文件InputStream(xml);
resources.put(xml.getName(),xmlStream);
resources.putAll(resourceFilesData);
for(Map.Entry数据:resources.entrySet()){
InputStream输入=data.getValue();
新的ZipEntry(data.getKey());
对于(int readNum=0;(readNum=input.read(buf))!=-1;){
write(buf,0,readNum);
}
zos.closeEntry();
input.close();
}
zos.close();
删除(xmlStream);
xml.delete();
}
跟踪:
我不知道这种行为的原因。但您可以尝试使用继承的类调试问题:

class FileInputStreamInh extends FileInputStream {

    public FileInputStreamInh(File file) throws FileNotFoundException {
        super(file);
    }

    @Override
    public void close() throws IOException {
        super.close();
        ^^^breakpoint here
    }
}

因此,您不应该创建
FileInputStream
,而应该创建
FileInputStream

请提供源代码和堆栈跟踪。我无法复制您的问题。哪一行是476?pack()函数从463开始。476-是嵌套循环。我已解除Bug并在一行中:resources.putAll(resourceFilesData);流已经关闭,甚至在我将它们放入新的容器2 Durandal之前,因为我还有导入功能,可以返回InputStream的映射。没有完整的来源,你怎么能判断一种风格?!如果你还没有回答我的具体问题-最好跳过。谢谢,它帮助了我。这是我的错——我早些时候关上了。
class FileInputStreamInh extends FileInputStream {

    public FileInputStreamInh(File file) throws FileNotFoundException {
        super(file);
    }

    @Override
    public void close() throws IOException {
        super.close();
        ^^^breakpoint here
    }
}