这是个比较晕人的异常!
在文件操作时,一般是用类似:
FileConnection fconn = (FileConnection)Connector.open("file:///CFCard/newfile.txt", Connector.READ_WRITE);
打开文件供读写。
一次我想我只需要写文件不需要读权限了,所以我把上述函数的参数Connector.READ_WRITE换成了Connector.WRITE。结果我得到了一个Exception——IllegalModeException!
JDE里面的描述如下:
If the application does have read access to the connection's target but has
opened the connection in Connector.WRITE
mode.
就是说我本来是有读权限的但是只使用了Connector.WRITE模式!我为什么需要读权限呢?————————
我用了FileConnection.exists()……原来FileConnection所有的状态检查的API都需要读权限!所以这个故事告诉我们,申请权限的时候别吝啬,该要的都给它要上,免得之后说咱权限不对!!!