Get the size of a resource

后端 未结 3 483
误落风尘
误落风尘 2021-01-18 05:28

I\'m using getClass().getResourceAsStream(path) to read from bundle resources.

How can I know the file size before reading the entire stream?

I

3条回答
  •  萌比男神i
    2021-01-18 06:03

    Naturally you cannot query the total size of a stream, since by definition it does not make the whole file available to you. Think of popping your hand in a river. You have a piece of the stream,but you have to put the entire river in your hand to know the total volume.

    In this case, you have to read the entire file as a stream and count the size. Remember you are dealing with classes and resources that may be part of a JAR file or other kind of compressed resource. The classloader does not have to provide a file handle to the resource in this case

提交回复
热议问题