How do I convert a String to an InputStream in Java

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

   This question already has an answer here:
    * /questions/247161/how-do-i-turn-a-string-into-a-inputstreamreader-in-java /questions/247161/how-do-i-turn-a-string-into-a-inputstreamreader-in-java 5 answers

Answers

Like this:

InputStream stream = new ByteArrayInputStream(exampleString.getBytes(StandardCharsets.UTF_8));

Note that this assumes that you want an InputStream that is a stream of bytes that represent your original string encoded as UTF-8 .

For java 6 replace StandardCharsets.UTF_8 with "UTF-8".

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/782178/how-do-i-convert-a-string-to-an-inputstream-in-java

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils