一、管道流
final PipedOutputStream pps = new PipedOutputStream();
final PipedInputStream pis = new PipedInputStream(pps);
new Thread(new Runnable() {
public void run() {
try {
pps.write("厲害了".getBytes(StandardCharsets.UTF_8));
pps.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
try {
int b3 = 0;
byte[] flush = new byte[1024];
while ((b3=pis.read(flush)) != -1) {
System.out.println(new String(flush, 0, flush.length));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
上面的管道流和Linux中的管道流是類似的
二、基本資料流
可以使用DataInputStream等及逆行基本資料的存盤
String address = "E:\\d05_gitcode\\Java\\newJava\\src\\com\\newJava\\newFile.txt";
DataInputStream dis = new DataInputStream(new FileInputStream(address));
byte b = dis.readByte();
System.out.println(b);
short s = dis.readShort();
System.out.println(s);
int i = dis.readInt();
System.out.println(i);
long l = dis.readLong();
System.out.println(l);
float f = dis.readFloat();
System.out.println(f);
double d = dis.readDouble();
System.out.println(d);
char c = dis.readChar();
System.out.println(c);
boolean bo = dis.readBoolean();
System.out.println(bo);
DataOutputStream dos = new DataOutputStream(new FileOutputStream(address));
dos.writeByte(1);
dos.writeShort(2);
dos.writeInt(3);
dos.writeLong(4L);
dos.writeFloat(5.0f);
dos.writeDouble(6.0d);
dos.writeChar(7);
dos.writeBoolean(false);

三、快取流
CPU運行速度是記憶體的幾百倍,是磁盤的幾百萬倍,因此減少和磁盤的互動,就能提高IO的速度,我們在這兩者之間提供一個buffer,快取流(也就是BufferedInputStream, BufferedOutputStream, BufferedReader, BufferedWriter), 來增多一次性讀寫的數量,減少IO的次數, 
四、列印流
我們所使用的System.out.println()方法就是列印流的一種
StringWriter sw = new StringWriter();
try (PrintWriter pw = new PrintWriter(sw)) {
pw.println("lisudfos");
}
System.out.println("lisudfos");
五、原始碼
github路徑:https://github.com/ruigege66/Java/blob/master/newJava/src/com/newJava CSDN:https://blog.csdn.net/weixin_44630050 博客園:https://www.cnblogs.com/ruigege0000/ 歡迎關注微信公眾號:傅里葉變換,個人賬號,僅用于技術交流 
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/393842.html
標籤:Java
