How can I get a java.io.InputStream from a java.lang.String?

前端 未结 8 851
悲&欢浪女
悲&欢浪女 2020-12-23 20:23

I have a String that I want to use as an InputStream. In Java 1.0, you could use java.io.StringBufferInputStream, but that has been @Deprecra

8条回答
  •  無奈伤痛
    2020-12-23 20:47

    Update: This answer is precisely what the OP doesn't want. Please read the other answers.

    For those cases when we don't care about the data being re-materialized in memory, please use:

    new ByteArrayInputStream(str.getBytes("UTF-8"))
    

提交回复
热议问题