Created
May 13, 2019 09:04
-
-
Save mike-neck/30caf5cd5afea246f20f1c53de0546a4 to your computer and use it in GitHub Desktop.
しかたがないにゃ〜
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.ByteArrayInputStream; | |
import java.io.ByteArrayOutputStream; | |
import java.io.InputStream; | |
import java.nio.charset.StandardCharsets; | |
class Scratch { | |
public static void main(final String[] args) { | |
final InputStream inputStream = new ByteArrayInputStream("foo,\nbar,\n,baz".getBytes(StandardCharsets.UTF_8)); | |
final String string = toString(inputStream); | |
System.out.println(string); | |
} | |
private static String toString(final InputStream inputStream) { | |
try(inputStream) { | |
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | |
inputStream.transferTo(outputStream); | |
return outputStream.toString(StandardCharsets.UTF_8); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment