Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

327
Vistas
How to convert a String to an InputStream in Kotlin?

I have a string:

var myString:String  = "My String"

How can I convert it to an InputStream in Kotlin?

over 4 years ago · Hanz Gallego
2 Respuestas
Responde la pregunta

0

val myString = "text"
val targetStream: InputStream = ByteArrayInputStream(initialString.toByteArray())

Pst. If you copy some java code, for example:

String myString = "text";
InputStream targetStream = new ByteArrayInputStream(myString.getBytes());

Android Studio will popup "Clipboard content seems to be Java code. Do you want to convert it to Kotlin?

over 4 years ago · Hanz Gallego Denunciar

0

Kotlin has an extension for String to convert directly.

val inputStream: InputStream = myString.byteInputStream()

The argument on byteInputStream is defaulted to charset: Charset = Charsets.UTF_8.

You can look at the extension by writing it and then cmd+click on it or in the package kotlin.io file IOStream.kt

Relying on the Java version is not wrong, but rather using a more kotlin idiomatic way when possible

over 4 years ago · Hanz Gallego Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda