0

I am attempting to read a number of files from a directory tree inside the Documents directory within my App andbox. Most of them are xml files which I read with :

NSData *data = [NSData dataWithContentsOfFile:packagefile. 
RXMLElement *rxml = [RXMLElement elementFromXMLData:data];

All but one them read OK. But one does not read and I get error code 256. For the bad file I can also try :

NSData *data = [NSData dataWithContentsOfFile:packagefile options:0 error:&err];

but the same error code comes back . (Hence I think my issue is not related to the actual xml content of the file).

Clearing out the sandbox and copying all the files back in programatically in my App makes no difference.

What can be wrong here? What else can I do?

4

1 回答 1

0

我找到了解决此问题的方法(“莫名其妙的错误代码 256”。)希望此解决方案对遇到此问题的其他开发人员有所帮助。

它已经用完了文件句柄。

在我的应用程序中,我还有一个日志记录功能,可以将活动记录到文件中(有点像 Log4J)。这需要每个记录的语句 - 使用“NSFileHandle”打开一个文件,然后是“seekToEndOfFile”,然后是“writeData”。

我错误地依赖 ARC 在退出日志记录过程时处理和关闭文件。显然 ARC 不会关闭文件,最终系统会耗尽文件句柄。

解决方案只是像在 Java 或 C 中那样调用“closeFile”。

于 2012-11-14T10:50:42.597 回答