As has been answered repeatedly, you can easily convert a String
to an InputStream
.
When browsing the Java 8 documentation I came across the long-deprecated StringBufferInputStream
class, which states that
As of JDK 1.1, the preferred way to create a stream from a string is via the
StringReader
class.
What is way is this referring to? There are several methods requiring classes in non-default libraries such as the error-prone ReaderInputStream
from Apache Commons IO, but I'm looking for the preferred way mentioned in the documentation. The solutions referenced in other questions are sufficient for my use cases, but I'd still like to know what the documentation is referencing.
Update
Apparently this is a 16 year old bug that hasn't been fixed. The proposed solution in the link is to use the deprecated class. I can't imagine that is what is intended from what the documentation says.