SyntaxHighlighter JS


Convert InputStream to String in two lines of code

Below is code to convert from into a String in just two line of Java 5 code.

public static String convertToString(InputStream in) {
    java.util.Scanner s = new java.util.Scanner(in).useDelimiter("\\A");
    return s.hasNext() ? : "";


Idea taken from "Stupid Scanner tricks"

No comments:

Post a Comment