单个输入流包含两个文件.我想分割这些文件 [英] Single inputstream containing two files. I want to split those files
本文介绍了单个输入流包含两个文件.我想分割这些文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Java中,我有一个inputstream
(也许是sequenceinputstream
),其中包含多个文件.我想使用Java分隔这些文件. java中有可用的解决方案吗?
In java I'm having an inputstream
(maybe sequenceinputstream
) containing more than one file. I want to separate those files using java. Is there any solution available in java?
推荐答案
简单的答案是:您不能/不应该.
The simple answer is: you can't / shouldn't.
复杂的答案:如果您正在处理SequenceInputStream
,则可以使用此反射技巧来访问基础流:
The complicated answer: in case you are dealing with a SequenceInputStream
, you can access the underlying streams using this reflection hack:
@SuppressWarnings("unchecked")
public static Enumeration<InputStream> split(final SequenceInputStream sis){
try{
Field streamsEnumField =
SequenceInputStream.class.getDeclaredField("e");
streamsEnumField.setAccessible(true);
return (Enumeration<InputStream>) streamsEnumField.get(sis);
} catch(final Exception e){
throw new IllegalStateException(e);
}
}
但是我会非常谨慎地使用这样的东西.
But I would be very careful about using something like this.
这篇关于单个输入流包含两个文件.我想分割这些文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文