用java编写linux设备

用java编写linux设备,java,linux,device,Java,Linux,Device,我试图在ubuntu中的char设备上读写,但当我创建outputstream时,我遇到了以下异常: java.io.FileNotFoundException:/dev/usb/legousbtower0设备或资源繁忙 这是我的代码: myInputStream = new FileInputStream("/dev/usb/legousbtower0"); myOutputStream = new FileOutputStream("/dev/usb/legousbtower0"); 输入

我试图在ubuntu中的char设备上读写,但当我创建outputstream时,我遇到了以下异常:

java.io.FileNotFoundException:/dev/usb/legousbtower0设备或资源繁忙

这是我的代码:

myInputStream = new FileInputStream("/dev/usb/legousbtower0");
myOutputStream = new FileOutputStream("/dev/usb/legousbtower0");
输入流工作,我可以使用终端向设备写入数据

回声测试>/dev/usb/legousbtower0


我尝试使用fuser检测设备的使用情况,但没有结果。

您是否尝试使用append=true打开它

myOutputStream = new FileOutputStream("/dev/usb/legousbtower0", true);

当您将设备作为输入流打开时,操作系统会将其标记为打开。由于一次只能有一个程序访问设备,因此第二次打开将失败。您需要以读写模式打开设备,可能需要使用
.

是的,这主要是猜测,我真的认为不会。谢谢!我使用了随机存取文件,一切都像一个符咒。