网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的范文:

 

标题 ios读取文件类和常用方法
范文
    第一、nsfilehandle
    nsfilemanager类主要对文件的操作(删除、修改、移动、复制等)
    nsfilehandle类主要对文件的内容进行读取和写入
    第二、nsfilehandle类处理文件的步骤
    创建一个nsfilehandle对象
    对打开的文件进行i/0操作
    关闭文件
    可以使用nsfilehandle进行断点续传
    第三、实现查找功能的代码:
    nsstring *homepath=nshomedirectory();
    nsstring *filepath=[homepath stringbyappendingpathcomponent:@desktop/hello.rtf];
    nsfilehandle *filehandle=[nsfilehandle filehandleforreadingatpath:filepath];
    nsuinteger length=[filehandle availabledata].length;
    [filehandle seektofileoffset:length/2];
    nsdata *data=[filehandle readdatatoendoffile];
    nsstring *str=[[nsstring alloc] initwithdata:data encoding:nsutf8stringencoding];
    nslog(@);
    第四、实现追加文件代码:
    nsstring *homepath=nshomedirectory();
    nsstring *filepath=[homepath stringbyappendingpathcomponent:@desktop/hello.rtf];
    nsfilehandle *filehandle=[nsfilehandle filehandleforupdatingatpath:filepath];
    //[filehandle seektoendoffile];
    [filehandle seektofileoffset:10];
    nsstring ;
    nsdata *data=[str datausingencoding:nsutf8stringencoding];
    [filehandle writedata:data];
    [filehandle closefile];
    // insert code here...
    nslog(@hello, world!);
    第五、实现复制文件的代码:
    nsstring *homepath=nshomedirectory();
    nsstring *filepath=[homepath stringbyappendingpathcomponent:@desktop/hello.rtf];
    nsstring *objpath=[homepath stringbyappendingpathcomponent:@desktop/copy.rtf];
    nsfilemanager *filemanager=[nsfilemanager defaultmanager];
    bool success=[filemanager createfileatpath:objpath contents:nil attributes:nil];
    nsfilehandle *writefile=[nsfilehandle filehandleforreadingatpath:filepath];
    nsfilehandle *objfile=[nsfilehandle filehandleforwritingatpath:objpath];
    [objfile readdatatoendoffile];
    nsdata *data=[writefile readdatatoendoffile];
    [objfile writedata:data];
    [writefile closefile];
    [objfile closefile];
随便看

 

在线学习网范文大全提供好词好句、学习总结、工作总结、演讲稿等写作素材及范文模板,是学习及工作的有利工具。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/17 0:34:46