Java 连接 Windows NamedPipe
废话不多说上代码
public static void main(String[] args) throws IOException { // 连接windows namedPipe RandomAccessFile pipe = new RandomAccessFile("\\\\.\\Pipe\\myPipe", "rw"); // 向 windows namedPipe 发送消息 byte[] message = "message".getBytes(StandardCharsets.UTF_8); pipe.write(message); // 接收 windows namedPipe 回复消息 byte[] buf = new byte[128]; pipe.read(buf); System.out.println(new String(buf)); // 关闭与 namedPipe 连接 pipe.close(); }