android - fopen() 不会重置文件
我正在使用一个本机库,它使用 fopen() 创建并写入二进制文件(网络日志文件)。我在 android 和 windows 上都使用这个库。在 Android 上,文件不会被删除 &在调用 fopen() 时创建,而在 Windows 上也是如此。这很麻烦,因为我希望每次启动程序时都将其重置;就像现在一样,当我在 Android 上运行记录器时,记录器只会累积数据。
我像这样 fopen() 文件;
#ifdef ANDROID
pcapFP = fopen("/mnt/sdcard/log.pcap","wb+");
#else
pcapFP = fopen("log.pcap","wb+");
#endif
知道为什么 Android 文件不重置吗?
谢谢
编辑:似乎如果进程被终止,那么文件会在重新启动应用程序时重置。但这还不够好,我想在需要时使用 *fopen()/fclose() 重置它。*
I am using a native library which creates and writes to a binary file(a network logging file) with fopen(). I am using this library on both android and windows. On Android, the file is not deleted & created upon calling fopen(), while it is so on windows. This is troublesome because I want it to be reset everytime I start the program; as it is now, the logger just accumulate data when I run it on android.
I fopen() the file like this;
#ifdef ANDROID
pcapFP = fopen("/mnt/sdcard/log.pcap","wb+");
#else
pcapFP = fopen("log.pcap","wb+");
#endif
Any idea why the Android file dosn't reset?
Thanks
EDIT: It seems that if the process is killed, then the file is reset upon restarting the app however. This is not good enough however, I want to reset it when I want with *fopen()/fclose().*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
标准在描述中特别指出
fopen
函数:,因此,显然,您的 Android 实现(编译器和库)不符合标准:(
尝试不同的编译也许是旗帜???
The Standard specifically says in the description of the
fopen
function:so, apparently, your Android implementation (compiler and library) is not Standard conformant :(
Try different compilation flags maybe???
删除文件怎么样。您可以在退出之前、阅读之前或应用程序启动时随时执行此操作。我看到你把它标记为c,这让我有点困惑,因为java通常用于android。
文件 file = new File(ih.getImgPath(id));
布尔值已删除= file.delete();
链接 1
链接 2
what about deleting the file. u can do it any time, prior to exitting, prior to reading, or as the app starts up. i see u labeled this as c which confuses me a little because java is usually used for android.
File file = new File(ih.getImgPath(id));
boolean deleted = file.delete();
LINK 1
LINK 2