Object-C,文件路径API
2015-11-29 14:00
489 查看
犀利吐槽1.同样都是“文件和目录操作",java中,就用java.util.File一个类,就封装了很多API,而Object-C搞了这么多类和函数。具体原因,有待分析啊。2.明明是NSString,字符串操作,怎么出现了”pathComponents“等操作文件路径相关的方法,很奇怪的赶脚。3.stringByAppendingString,这函数的名字有点长啊。4.总体感觉,Object-C的语法比Java复杂一些,码代码的效率低了不少。
/
程序输出2015-11-29 13:43:30.550 FilePathUtil[2861:179163] The tempDir is /var/folders/4q/5ylpds9n5n97bq_r41qvly4w0000gn/T/2015-11-29 13:43:30.551 FilePathUtil[2861:179163] The base dir is Debug2015-11-29 13:43:30.551 FilePathUtil[2861:179163] The fullPath is /Users/fansunion/Library/Developer/Xcode/DerivedData/FilePathUtil-bvzjqehotbexooebruphtwcmqekz/Build/Products/Debugpath.m2015-11-29 13:43:30.551 FilePathUtil[2861:179163] The extentions is m2015-11-29 13:43:30.552 FilePathUtil[2861:179163] The home directory is /Users/fansunion2015-11-29 13:43:30.552 FilePathUtil[2861:179163] /2015-11-29 13:43:30.552 FilePathUtil[2861:179163] Users2015-11-29 13:43:30.553 FilePathUtil[2861:179163] fansunionProgram ended with exit code: 0
/
/ // main.m // FilePathUtil // // Created by fansunion on 15/11/29. // Copyright (c) 2015年 demo. All rights reserved. // #import <Foundation/Foundation.h> //演示文件路径API int main(int argc, const char * argv[]) { @autoreleasepool { NSString *fileName =@"path.m"; NSFileManager *fm; NSString *path,*tempDir,*extention,*homeDir,*fullPath; NSArray *components; fm =[NSFileManager defaultManager]; //临时目录 tempDir = NSTemporaryDirectory(); NSLog(@"The tempDir is %@",tempDir); //提取基本目录 path =[fm currentDirectoryPath]; NSLog(@"The base dir is %@",[path lastPathComponent]); //fileName在当前目录中的完整路径 //这个地方有个问题 //本地输出”/Users/fansunion/Library/Developer/Xcode/DerivedData/FilePathUtil-bvzjqehotbexooebruphtwcmqekz/Build/Products/Debugpath.m“ //Debug和path.m之间没有”分隔符“/",而书本中的例子是有的 //最好还是手动加上,Java中也是没有这个分隔符,需要手动加上的 fullPath =[path stringByAppendingString:fileName]; NSLog(@"The fullPath is %@",fullPath); //获得文件扩展名 extention = [fullPath pathExtension]; NSLog(@"The extentions is %@",extention); //获得用户的主目录 homeDir = NSHomeDirectory(); NSLog(@"The home directory is %@",homeDir); //拆分路径为各个组成部分 components = [homeDir pathComponents]; for(path in components){ NSLog(@"%@",path); } } return 0; }
程序输出2015-11-29 13:43:30.550 FilePathUtil[2861:179163] The tempDir is /var/folders/4q/5ylpds9n5n97bq_r41qvly4w0000gn/T/2015-11-29 13:43:30.551 FilePathUtil[2861:179163] The base dir is Debug2015-11-29 13:43:30.551 FilePathUtil[2861:179163] The fullPath is /Users/fansunion/Library/Developer/Xcode/DerivedData/FilePathUtil-bvzjqehotbexooebruphtwcmqekz/Build/Products/Debugpath.m2015-11-29 13:43:30.551 FilePathUtil[2861:179163] The extentions is m2015-11-29 13:43:30.552 FilePathUtil[2861:179163] The home directory is /Users/fansunion2015-11-29 13:43:30.552 FilePathUtil[2861:179163] /2015-11-29 13:43:30.552 FilePathUtil[2861:179163] Users2015-11-29 13:43:30.553 FilePathUtil[2861:179163] fansunionProgram ended with exit code: 0
相关文章推荐
- Object-C,文件路径API
- Object-C,文件路径API
- 从今天开始学习ios,入门第一天(Object-C学习笔记)自动引用计数和为类添加属性
- Object-C,遍历目录
- Object-C,遍历目录
- Object-C,遍历目录
- object-c之时间选择器UIDatePicker和UIpickerview筛选器
- object-c之时间选择器UIDatePicker和UIpickerview筛选器
- object-c之UItableView下拉刷新
- object-c之UItableView下拉刷新
- Objective-C学习 - KVO
- objc_setAssociatedObject 1
- objc_setAssociatedObject
- 【转载】html中object标签详解
- 从今天开始学习ios,入门第二天(Object-C学习笔记)内存管理
- 从今天开始学习ios,入门第一天(Object-C学习笔记)
- Objective-C 异常处理
- Objective-C 类型判断
- Object的clone()方法、深拷贝、浅拷贝
- Qt Object 类简介--Qt 类简介专题(二)