2011-10-03 98 views
0

我使用fileconnection获取缩略图图像。FileIOException:黑莓文件已存在错误

我使用线程构造函数获取图像。我通过网址并获取图像。

如果两个图像的URL一样,我得到异常 “FileIOException:文件已存在”

我的代码是在这里,

FileConnection fConn = null; 
try 
{ 
     String fileString = MD5.encodeStringMD5(url); 
     fConn = (FileConnection) Connector.open(fileTempPath+fileString+".png"); 
     if(!fConn.exists()) 
     { 
       fConn.create(); 
       GetImageFromURL(url,fConn,id); 
     } 
     else 
     { 
       GetImageFromFolder(fConn, id); 
     } 
     fConn.close(); 
} 
catch (Exception e) 
{ 
     System.out.println("------"+e); 
} 

如果URL是不同的。没有问题发生。但是如果两个或三个url相同,只有一个图像仅存储并加载在屏幕上。其他网址不显示。

存储在设备存储器中后,其加载所有图像。

异常抛出此行 - “fConn.create();”

回答

1

在创建新文件之前,尝试打开具有相同名称/路径的文件。如果它已经存在删除它。

+0

嗨。我检查文件连接if(!fConn.exists()) {} – RVG

+0

使用System.out.println和/或EventLogger类记录您用于打开/检查文件存在的完整路径。并使用此信息手动检查文件存在。当你调用!fConn.exist()或不。 – 2011-10-03 09:11:49

+0

我创建一个线程类并为该线程类创建五个对象。我通过网址。当一个fconn创建并准备写入它时,同时第二个对象在线程中调用,如果fcon相同,则发生错误。 – RVG

1

如果文件已经存在那么这样做:

if(!fConn.exists()) 
    { 
      fConn.create(); 
      GetImageFromURL(url,fConn,id); 
    } 
    else 
    { 
      fConn.truncate();//it removes the data in that file; 
      GetImageFromFolder(url,fConn, id); 
    }