就是将内容写入到内存中,并从内存中取出,是用的是ByteArrayInputStream 和 ByteOutputStream 类:
范例:
package haizhu.com.byteArrayStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; public class ByteArrayDemo { public static void main(String[] args) { String str = "HELLOWORLD"; ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes()); ByteArrayOutputStream bos = new ByteArrayOutputStream(); int temp = 0; while((temp = bis.read())!= -1){ char c = (char)temp; bos.write(Character.toLowerCase(c)); } String newStr = bos.toString(); try{ bis.close(); bos.close(); }catch(IOException e){ e.printStackTrace(); } System.out.println(newStr); } }