0
我有一个进程将数据库中的文件与文件夹同步。只有低于50000个文件同步。有些文件完全同步;但是,在一个文件上,我收到一个未找到文件的例外。我检查父目录是否存在,如果不存在,我创建它。将文件写入现有文件夹时发现JAVA FileNotFound
文件写入代码如下:
for(Map<String,Object> file: fileList)
{
createDirectory(file); //Creates the directory
Blob outBlob = (Blob)file.get("fileData");
InputStream is = outBlob.getBinaryStream();
FileOutputStream fos = new FileOutputStream((String)file.get("path"));
int b = 0;
while ((b = is.read()) != -1)
{
fos.write(b);
}
fos.flush();
fos.close();
}
而且createDirectory方法:
public static void createDirectory(Map<String,Object> file) throws IOException
{
// Create parent directory - If directory does not exist
File directory = new File(file.get("parent"));
if (!directory.exists())
{
System.out.println("Parent Directory does not exist, creating ...");
// ...create it
if (!directory.mkdirs())
{
System.out.println("Parent Directory creation failed ...");
}
}
}
这是给人的FileNotFoundException异常
FileOutputStream fos = new FileOutputStream((String)file.get("path"));
父目录是行C:\ temp \
我对上述文件夹有权限。
createDirectory方法不会将任何内容记录到控制台,因为该目录确实存在。
我已经搜索了几天,无法看到为什么这一个文件将失败,而其他成功。 任何帮助,将不胜感激。
上面的代码已被修剪并且变量名称已更改。由于安全原因,我不允许给出堆栈跟踪。我试图复制错误,但没有这样做的运气。
PS这是我第一次问stackoverflow,请原谅我,如果我打破了一些标准规则。
问候,
请你给更喜欢什么ü在地图<字符串,对象>提供的对象信息.. –
你需要给我们,让你这个错误的文件的实际名称,即'file.get(“path”)'返回的字符串。它有效吗?它是否与已经存在的目录相同?这是代码不如其运行的确切上下文重要的一种情况。 –
谢谢。我担心这是一个我一直想念的代码问题。对于Map文件失败的文件,包含:“parent”:“C:\\ temp \\”,“fileData”:(文件字节),“path”:“C:\\ temp \\ PosNewBussinessDocument.PDF“ –
Infinity