我有一个程序,可以创建一些文件,将它们放入目录,然后读取它们并将其发送给接收器。
每次发送文件后,它都会被删除。
然而,在第一包文件被发送后,程序无法读取任何其他文件,对于每个新文件,我都会收到此错误:
java.io。文件未找到异常:UBX_MSG。bin(系统找不到指定的文件)
每次读取文件器时,我都会检查它们是否确实存在,并且该方法总是返回true。
谁能解释一下这个问题吗?
任何帮助都将不胜感激。非常感谢。
这是我的函数,一个是读取文件,另一个是发送文件。
public void push2rec (File[] LOF){
try {
for (File f : LOF){
System.out.println(f.exists());
byte[] rd = read(f.getName());
SP.writeBytes(rd);
f.delete();
}
}
catch (SerialPortException ex) {System.out.println(ex);}
}
public static byte[] read(String name){
File file = new File(name);
byte[] bytes = new byte[(int) file.length()];
try {
FileInputStream inputStream = new FileInputStream(file);
inputStream.read(bytes);
inputStream.close();
}
catch (FileNotFoundException ex) {System.out.println(ex);}
catch (IOException ex) {System.out.println(ex);}
return bytes;
}