1.字符串转inputStream
- String string;
- //......
- InputStream is = new ByteArrayInputStream(string.getBytes());
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- int i;
- while ((i = is.read()) != -1) {
- baos.write(i);
- }
- String str = baos.toString();
- System.out.println(str);
- OutputStream os = System.out;
- os.write(string.getBytes());
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- //向OutPutStream中写入,如 message.writeTo(baos);
- String str = baos.toString();