我的世界什么颜色的马好

阿卡每天写写写 阿卡每天写写写
回答
  • 慕慕 慕慕

    nsfilemanager*filemanager=[nsfilemanager defaultmanager];nsstring*str1=nshomedirectory();filepath=[[nsstring stringwithformat:@"%documents/imageviews/test.pl**t",str1]retain];nslog(@"%",_filepath);if![filemanager fileex**tsatpath:_filepath]){/如果不存在,则说明是第一次运行这个程序,那么建立这个文件夹
    nslog(@"first run");nsstring*path=[nshomedirectory()stringbyappendingpathcomponent:@"documents"];nsstring*directrypath=[path stringbyappendingpathcomponent:@"imageviews"];[filemanager createdirectoryatpath:directrypath withintermediatedirectories:yes attributes:nil error:nil];nsstring*filepath=[directrypath stringbyappendingpathcomponent:@"test.pl**t"];nslog(@"%",filepath);[filemanager createfileatpath:filepath contents:nil attributes:nil];}
    此段代码创建的filepath为
    users/yuqiu/library/application support/iphone simulator/6.1/applications/2a8efe9e-4cca-41d1-8a5f-1ff00a115fa3/documents/imageviews/test.pl**t
    一、创建~/documents/imageviews/test.pl**t的详细步骤
    1、找到docume**s目录所在的位置
    nsstring*str1=nshomedirectory();str1为/users/yuqiu/library/application support/iphone simulator/6.1/applications/2a8efe9e-4cca-41d1-8a5f-1ff00a115fa3
    2、加上docume**s这层目录
    nsstring*path=[nshomedirectory()stringbyappendingpathcomponent:@"documents"];path为/users/yuqiu/library/application support/iphone simulator/6.1/applications/2a8efe9e-4cca-41d1-8a5f-1ff00a115fa3/documents
    注意:使用的是stringbyappendingpathcomponent:方法,不需要加“/;如果用的是别的方法加的话,需要写成@"/documents".
    ps:这里1、2两步可以简化为
    nsarray*paths=nssearchpathforderictoriesindomains(nsdocumentdirectory,nsuserdomainmask,yes);nsstring*path=[paths lastobject];3、在docume**s目录中创建名为imageviews的目录
    nsfilemanager*filemanager=[nsfilemanager defaultmanager];nsstring*directrypath=[path stringbyappendingpathcomponent:@"imageviews"];[filemanager createdirectoryatpath:directrypath withintermediatedirectories:yes attributes:nil error:nil];创建nsfilemanager的实例filemanager.nsfilemanager这个类是专门进行文件管理的,可以创建文件,目录,遍历目录等。我们调用了 createdirectoryatpath:方法创建了一个新目录。4、在imageviews目录里,创建文件test.pl**t.
    nsstring*filepath=[directrypath stringbyappendingpathcomponent:@"test.pl**t"];[filemanager createfileatpath:filepath contents:nil attributes:nil];调用createfileatpath:创建文件
    最后得到的整个文件路径为:
    二、nsfilemanager常用的文件管理操作
    1、创建目录 createdirectoryatpath:
    2、创建文件 createfileatpath:
    3、删除某个文件 removeitematpath:
    4、检查某个文件是否存在 fileex**tsatpath:
    5、检查文件是否可读 **readablefileatpath:
    是否可写:**writablefileatpath:
    6、取得文件属性 fileattributesatpath:
    改变文件属性changeattributesatpath:
    7、从path代表的文件中读取数据:contentsatpath
    8、移动文件movepath:topath:handler:
    9、复制文件copypath:topath:handler:

类似问答
精品推荐

友情链接

友链互换QQ:

谷财 备案编号:蜀ICP备11019336号-3商务合作:235-677-2621

Copyright 2009-2020 Chengdu Sanzilewan Technology Co.,Ltd all rights reserve

抵制不良游戏 拒绝盗版游戏 注意自我保护 谨防受骗上当 适度游戏益脑 沉迷游戏伤身 合理安排时间 享受健康生活