安卓ios文件读写的存放

1.从bundle中读取文件

	NSString *path = [[NSBundle mainBundle] pathForResource:@"outfile.pcm" ofType:nil];

2.使用沙盒路径做存储数据

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) ;
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *filePath = [documentsDirectory stringByAppendingString:@"/sdcard1.pcm"];

3.读取bundle文件变成流送出去

    NSString *path = [[NSBundle mainBundle] pathForResource:@"outfile.pcm" ofType:nil];
    static FILE* pcm = NULL;
    char buff[512];
    if(NULL == pcm)
        pcm = fopen((char *)[path UTF8String], "rb");
    if (pcm != NULL) {
        while (!feof(pcm)) {
            int count = fread(buff, (size_t)sizeof(char), 512, pcm);
             NSLog(@"count=%d",count);
             usleep(1000*100);
        }
        fclose(pcm);
    }

4.流写入沙盒文件

    char decodeBuffer[640];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) ;
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *filePath = [documentsDirectory stringByAppendingString:@"/sdcard1.pcm"];
    static FILE* h264 = NULL;
    if(NULL == h264)
        h264 = fopen((char *)[filePath UTF8String], "wb");
    if(NULL != h264)
    {
        fwrite(decodeBuffer, frameSize, 1, h264);
        fflush(h264);
    }

5.安卓的模拟器不需要写到bundle 里面
而是写到模拟器路径下(夜神模拟器)
安卓需要增加权限AndroidManifest.xml

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

安卓的路径"/mnt/shared/Other/outfile.pcm" 读写都是

    static FILE *pcmFile = NULL;
    if (pcmFile == NULL) {
        pcmFile = fopen("/mnt/shared/Other/outfile.pcm","wb");
    }
    if (pcmFile != NULL){
        fwrite(outBuffer,size*2,1,pcmFile);
        fflush(pcmFile);
    }

读取文件也是这个
真实路径在
/Users/yeyibo/Library/Application\ Support/Nox\ App\ Player/Nox_share/Other/outfile.pcm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值