【发布时间】:2011-08-26 05:43:46
【问题描述】:
我开发了一个黑莓应用程序,其中我有视频控制来捕获图像然后我将图像以我想要的名称保存在根目录中并显示屏幕...在重新捕获按钮中单击我再次捕获再次图像,我正在删除以前的图像并使用文件连接将新图像以相同的名称保存在相同的路径中。我的问题是它在模拟器中工作正常。但是当我在设备中测试时,当我尝试删除以前的图像以保存新图像时,它会抛出错误。它会抛出“net.rim.device.api.io.file.fileioexception:文件正在使用中” ..请帮帮我..
@arhimed, @juanmabaiu 这是在设备中测试时捕获并抛出异常的函数。
public void fieldChanged( final byte[] _raw )
{
try
{
flag ++;
// Create the connection to a file that may or
// may not exist.
FileConnection file = (FileConnection)Connector.open(FILE_NAME + "_front" + EXTENSION);
// If the file exists, increment the counter until we find
// one that hasn't been created yet.
while( file.exists() )
{
file.delete();
file = (FileConnection)Connector.open( FILE_NAME + "_front" + EXTENSION );
}
//FileConnection file_temp = (FileConnection)Connector.open(FILE_NAME + "tempimg" + EXTENSION);
//file_temp.delete();
// We know the file doesn't exist yet, so create it
file.create();
// Write the image to the file
OutputStream out = file.openOutputStream();
out.write(_raw);
// Close the connections
out.close();
file.close();
//Dialog.inform( "Saved to " + FILE_NAME + "_front" + EXTENSION );
}
catch(Exception e)
{
home.errorDialog("ERROR " + e.getClass() + ": " + e.getMessage());
Dialog.inform( "File not saved this time");
}
}
【问题讨论】:
-
确保您在保存或删除文件后关闭了所有流。
-
试试 Arhimed 在上述评论中所说的话。如果它不能修复它,请添加一些代码。
-
hi arhimed 和 juanmabaiu.. 代码中的一切都很好.. 它在模拟器中完美运行。仅在设备中测试时显示错误..
标签: blackberry