废话不多说,直接上demo
demo
public class IoController {
public static void main(String[] args) {
System.out.println(readContentByInputStream());
}
public static String readContentByInputStream() {
InputStream inputStream = new ByteArrayInputStream("水电费第三方sad".getBytes());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int i = -1;
try {
while ((i = inputStream.read()) != -1) {
bos.write(i);
}
} catch (Exception e) {
}
return bos.toString();
}
public static InputStream gerInputStreamByString(String str) {
InputStream inputStream = new ByteArrayInputStream("水电费第三方sad".getBytes());
return inputStream;
}
}