public class InputStreamTest {
public static void main(String[] args) throws IOException{
byte[] data = { 72, 101, 108, 108, 111, 33 };
try (InputStream input = new ByteArrayInputStream(data)) {
String s = readAsString(input);
System.out.println(s);
}
try(InputStream input2=new FileInputStream("d:/iotest/test1.txt"))
{
int n;
byte[] buffer=new byte[1000];
while((n=input2.read(buffer))!=-1)
{
System.out.println(n);
}
}
}
public static String readAsString(InputStream input) throws IOException {
int n;
StringBuilder sb = new StringBuilder();
while ((n = input.read()) != -1) {
sb.append((char) n);
}
return sb.toString();
}
}