Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

326
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda