final PipedOutputStream pps = new PipedOutputStream(); final PipedInputStream pis = new PipedInputStream(pps); new Thread(new Runnable() { publicvoidrun(){ try { pps.write("厉害了".getBytes(StandardCharsets.UTF_8)); pps.close(); } catch (IOException e) { e.printStackTrace(); } } }).start();
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);