JNI中新建文件、读写普通文件和驱动文件的方法综述fopen/open/creat/
来源:互联网 发布:游戏台式机推荐 知乎 编辑:程序博客网 时间:2024/05/05 07:42
这段时间的JNI开发中发现,在JNI中,普通文件的新建、读写既可以用C库函数,也可以用linux系统函数,如下:
平台android 4.4.2
编译工具ndk
static int write_file(void){int fd = 0;int ret = 0;char str[32];FILE *fp = NULL;//C库函数新建、写LOGI("fuck1.txt\n");fp = fopen("/storage/sdcard0/Download/fuck1.txt", "a");ERROR(fp == NULL, err1, "fuck1.txt create file");fprintf(fp, "%s\n", "fuck always!\n");fclose(fp);//linux系统函数open新建、写#if 1LOGI("fuck2.txt\n");fd = open("/storage/sdcard0/Download/fuck2.txt", O_CREAT | O_WRONLY, 0644);ERROR(fd < 0, err1, "fuck2.txt open file");strcpy(str, "hello world!\n");ret = write(fd, str, strlen(str));LOGI("2 write bytes =%d\n", ret);close(fd);#endif//linux系统函数creat/open 新建、写LOGI("fuck3.txt\n");fd = creat("/storage/sdcard0/Download/fuck3.txt", 0644);ERROR(fd < 0, err1, "fuck3.txt creat file");fd = open("/storage/sdcard0/Download/fuck3.txt", O_WRONLY);ERROR(fd < 0, err1, "fuck3.txt open file");strcpy(str, "fuck world!\n");ret = write(fd, str, strlen(str));LOGI("3 write bytes =%d\n", ret);close(fd);return 0;err1:return -1;}
在上面这个应用中,linux系统函数open的两个方法都可以成功使用:
<span style="white-space:pre"></span>int open(const char *pathname, int flags); <span style="white-space:pre"></span>int open(const char *pathname, int flags, mode_t mode);
其中两个参数的open调用需要和creat函数结合使用。
但是在JNI中操作驱动设备文件时,则只能使用两个参数的open来打开,不能使用三个参数的open来打开!!!
因为我直接把ubuntu的程序(可以打开)移植到JNI中,一直open(三个参数的)失败,后来我改成了两个参数的open就可以打开。
这个问题先放着,后面再细究其原因!
JNI程序:
int V4l2::v4l2_open(struct video_information *vd_info){ERROR(NULL == vd_device, err1, "video device name NULL!");LOGI("video name = %s\n", vd_device);vd_info->fd = open(vd_device, O_RDWR); if(vd_info->fd < 0) { LOGE("open: failed!"); return -1; } return 0;err1:return -1;}
0 0
- JNI中新建文件、读写普通文件和驱动文件的方法综述fopen/open/creat/
- 文件IO(1)--creat和open
- c语言读写文件fopen和fopen
- 文件操作open , close, creat
- fopen读写文件
- fopen文件读写函数
- 文件读写fopen()
- open和fopen的区别:(怎样获取文件…
- 驱动中读写文件
- arm应用程序之文件读写操作差异open与fopen
- .verilog系统任务读写文件$fopen和$fdisplay的使用
- Minix创建文件:creat,open操作
- Linux 文件 open,creat,write,read (C)
- Linux 使用creat和open创建文件时参数mode的值
- 位图文件读写综述
- 位图文件读写综述
- 位图文件读写综述
- 位图文件读写综述
- 数据库的一些知识点
- Nginx服务器安全配置详解
- 【C++基础之二】常量指针和指针常量
- 佛祖保佑 永无BUG
- 共创云端新业态,AppCan移动云大会即将召开
- JNI中新建文件、读写普通文件和驱动文件的方法综述fopen/open/creat/
- 10002---一篇很全面的freemarker教程
- 存储小数的时候尽量用定点数来表示
- 函数式编程:Functor、Applicative 和 Monad
- 用AndroidStudio导入github项目
- nodejs 不错的在线教程!
- ccs5.5.0修改背景主题颜色,安装theme color
- php单引号和双引号区别
- ncurses中的输出函数