问题
I am trying to encrypt an InputStream
which I am getting from FileItem.getInputStream();
and I want to know the encrypted stream's length.
If it would be a simple FileInputStream
, I could have tried File#length()
or FileInputStream#getChennal().size()
though not sure even those would have given me exactly what I want, but, in this case what I have is an InputStream
(the encrypted one) and I want to find length of the same, I tried searching on Internet but there I could not find any efficient solution to that.
Please help
回答1:
You have to read the whole stream for that. Streams are probably not even complete when you start reading from them, so the size may not be known at that time.
回答2:
You can output whats in InputStream and get the length
ObjA = new ObjA;
while( more message to read ){
ObjA = inputStreamObj.read();
}
System.out.println(ObjA.length());
来源:https://stackoverflow.com/questions/22508428/get-size-of-inputstream-in-java