首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

读取资料操作

2012-10-29 
读取文件操作//获取路径NSString *path[[NSBundle mainBundle]pathForResource:@"file3" ofTyp

读取文件操作
//获取路径
NSString *path=[[NSBundle mainBundle]pathForResource:@"file3" ofType:@"dmh"];
//NSLog(@"path:%@",path);
//转换
unsigned int lenOfstrValue = [path length];
char szValue[lenOfstrValue + 1];
strcpy(szValue, [path cString]);

//printf("message:%s\n",szValue);

FILE *wordFile=fopen(szValue,"r");

byte *data=malloc(sizeof(byte) * length1);
if (wordFile == nil) {
NSLog(@"can not open this file .\n");
exit(0);
}else {
if (offset>0) {
//跳过offset这么长,0表示从开始跳
fseeko(wordFile,offset,0);
}

}
//获取文件长度
//            移到最后跳ol
//fseek(wordFile,0L,SEEK_END);
//            获取文件长度
//long t=ftell(wordFile);
//移到开始跳offset
//fseek(wordFile, offset, SEEK_SET);
//获取文件长度,在这之前要移到文件最后
//long tt=ftell(wordFile);
//读取长度
int ass=fread(data,length1,1,wordFile);
//关闭文件流
fclose(wordFile);

热点排行