// Create an InputStream object InputStream inputStream = new FileInputStream("file.txt"); // Convert the InputStream to String String text = inputStream.toString(); System.out.println(text);
// Create an InputStream object InputStream inputStream = new ByteArrayInputStream("Hello, world!".getBytes()); // Convert the InputStream to String String text = inputStream.toString(); System.out.println(text);This example creates an InputStream object from a String containing the text "Hello, world!". The toString() method is then used to convert the InputStream to a String, which is printed to the console. The java.io.InputStream class is part of the Java standard library.