gpt4 book ai didi

Java:FileOutputStream 和 FileInputStream 一起位于同一个文件上

转载 作者:行者123 更新时间:2023-12-01 19:37:29 25 4
gpt4 key购买 nike

我可以打开一个文件(linux字符设备)进行读+写,并使用这两个类来实现像客户端-服务器这样的对话框吗?

类似这样的事情:

File file = new File("/dev/ttyS0");  
FileOutpuStream fo = new FileOutputStream(file)
FileInputStream fi = new FileInputStream(file)

完成上述声明后,我可以连续向该文件发送轮询(问题)并读取其回复吗? (当然,附加到ttyS0还有一种服务器)

最佳答案

我无法测试它,但您可能想尝试一下RandomAccessFile。它不提供创建流的操作,但它实现了 DataInput 和 DataOutput。这也许足以满足您的目的? RandomAccessFile docs

String file = "/dev/ttyS0";
try {
RandomAccessFile f = new RandomAccessFile(file, "rwd");
} catch (IOException e){
e.printStackTrace();
}

关于Java:FileOutputStream 和 FileInputStream 一起位于同一个文件上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56920916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com