我有一个程序,可以创建一些文件,将它们放到目录中,然后读取它们并发送给接收者。每次发送一个文件之后,它就会被删除。但是,在第一包文件发送后,程序无法读取任何其他文件,对于每个新文件,我将得到以下错误:
java.io.FileNotFoundException: 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;
}发布于 2016-03-20 11:28:36
f.getName()只保留不带路径的文件名。使用f.getAbsolutePath()。
https://stackoverflow.com/questions/36112735
复制相似问题