使用 J2ME 删除文件会引发 IOException
我尝试使用 J2ME 的 FileConnection.delete() 方法删除文件,但每次调用 delete() 方法时都会抛出 IOException。 我编写了一个条件语句来验证文件是否存在,但不管事实如何,都会引发 IOException。
根据 FileConnection API,当对 FileConnection 对象调用 delete() 时,与该对象关联的所有流都将关闭,并且如果对与特定文件关联的流发生任何后续操作,则会引发 IOException。
我尝试删除的文件已记录在同一个程序中,但在调用delete()方法后,我调用了recordControl.reset()。 这可能会导致抛出 IOException 吗?
我的问题可能是什么?
I am attempting to delete a file using J2ME's FileConnection.delete() method, but I an IOException is being thrown each time I call the delete() method. I have written a conditional statement to verify the existence of the file, but irregardless of that fact, an IOException is thrown.
According to the FileConnection API, when delete() is called on a FileConnection object, all streams associated with the object are closed, and an IOException is thrown if any subsequent actions on the streams associated with the particular file occur.
The file I am attempting to delete has been recorded within the same program, but after I call the delete() method, I call recordControl.reset(). Would this probably cause the IOException to be thrown?
What could be my problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信您的代码中的某个人已连接到您要删除的文件。 您应该手动关闭与现有文件的所有连接,并且不要相信其他人会为您执行此操作。
您是否已在其他应用程序(例如记事本)中打开该文件?
I believe that someone in your code is connected to the file you want to delete. You should manually close all connections to the existing file and not trust that someone else will do this for you.
Do you have open the file in another application, like notepad?
异常堆栈跟踪会告诉您哪一行代码抛出 IOException,有时您还会得到异常的原因,因此请查看堆栈跟踪。
IThe exception stack trace will tell you what line of code is throwing IOException and some times you get reason of exception as well, so have a look at the stack trace.
检查字符串,包括您传递给 Connector.open() 的路径
,验证文件权限,删除之前关闭该文件打开的所有流。
Check the string including the path that you are passing to Connector.open()
,Verify the file permissions,close all streams opened for that file before deleting.