Object-C,文件路径API
犀利吐槽
1.同样都是“文件和目录操作",java中,就用java.util.File一个类,就封装了很多API,而Object-C搞了这么多类和函数。具体原因,有待分析啊。
2.明明是NSString,字符串操作,怎么出现了”pathComponents“等操作文件路径相关的方法,很奇怪的赶脚。
3.stringByAppendingString,这函数的名字有点长啊。
4.总体感觉,Object-C的语法比Java复杂一些,码代码的效率低了不少。
/
/
// 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 Debug
2015-11-29 13:43:30.551 FilePathUtil[2861:179163] The fullPath is /Users/fansunion/Library/Developer/Xcode/DerivedData/FilePathUtil-bvzjqehotbexooebruphtwcmqekz/Build/Products/Debugpath.m
2015-11-29 13:43:30.551 FilePathUtil[2861:179163] The extentions is m
2015-11-29 13:43:30.552 FilePathUtil[2861:179163] The home directory is /Users/fansunion
2015-11-29 13:43:30.552 FilePathUtil[2861:179163] /
2015-11-29 13:43:30.552 FilePathUtil[2861:179163] Users
2015-11-29 13:43:30.553 FilePathUtil[2861:179163] fansunion
Program ended with exit code: 0
最新文章
- JS学习:第一周——NO.3面向对象
- Ajax JQuery HTML 提交上传文件File HTML+ Ajax+ASP.NET+ WebService
- JavaScript - 2个等号与3个等号的区别
- Linux Linux程序练习九
- C++中尖括号和引号的区别---转载
- 初学tornado之MVC版helloworld
- volatile之一--volatile不能保证原子性
- php中的foreach函数
- C# 6 与 .NET Core 1.0 高级编程 - 41 ASP.NET MVC(上)
- linux下大于2T的硬盘格式化方法
- CSS3 column属性
- Prefer ThreadLocalRandom over Random
- C# 将datatable导出成Excel
- 偏门却又实用的 CSS 样式
- 阅历>;感悟
- [LeetCode&;Python] Problem 720. Longest Word in Dictionary
- apache的bin目录下的apxs有什么作用? PHP模块加载运行方式
- VMWare常用快捷键
- MongDB篇,第一章:数据库知识1
- Vue 1.0 和 2.0 执行顺序
热门文章
- Android 解决下拉刷新控件和ScrollVIew的滑动冲突问题。
- HDU 1312 Red and Black【DFS】
- POJ 1198 / HDU 1401 Solitaire (记忆化搜索+meet in middle)
- 虚拟集群LVS及DR模式搭建笔记
- 2015,鬼王Xun和GGL比赛,带给我们无尽的欢乐
- Android群英传-拼图游戏puzzle-6点吐槽
- NYIST 531 太空飞行计划
- 洛谷——P3370 【模板】字符串哈希
- HTTP Analyzer(实时分析HTTP/HTTPS数据流)
- 13款用于拍摄全景照片的iOS应用