犀利吐槽

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

Object-C,文件路径API的更多相关文章

  1. C#常见的文件路径Api

    我们经常有遇到要处理文件路径的需求,那么一般我们常见的有几种: 程序下面的文件 临时目录下的文件 获取程序下面的文件 首先我们创建了实例解决方案: 其中调用链是:Main.Shell->FooA ...

  2. Android用路径api在内部存储读写文件

    复制并修改原有项目 复制之前创建的项目CC+CV操作 需要改动的地方: * 项目名字 * 应用包名 * R文件重新导包 接着修改件/AndroidManifest.xml中的包名:package=&q ...

  3. LoadLibrary文件路径及windows API相关的文件路径问题

    LoadLibrary HMODULE WINAPI LoadLibrary( _In_  LPCTSTR lpFileName ); Loads the specified module into ...

  4. windows API实现用户选择文件路径的对话框

    在编写应用程序时,有时需要用户选择某个文件,以供应用程序使用,比如在某些管理程序中需要打开某一个进程,这个时候需要弹出一个对话框来将文件路径以树形图的形式表示出来,以图形化的方式供用户选择文件路径,而 ...

  5. 01 语言基础+高级:1-5 常用API第二部分_day01.【Object类、常用API: Date类、System类、StringBuilder类】

    day01[Object类.常用API] 主要内容 Object类 Date类 DateFormat类 Calendar类 System类 StringBuilder类 包装类 java.lang.O ...

  6. Spring配置文件详解 - applicationContext.xml文件路径

    spring的配置文件applicationContext.xml的默认地址在WEB-INF下,只要在web.xml中加入代码 org.springframework.web.context.Cont ...

  7. Android根据文件路径加载指定文件

    Android根据指定的文件路径加载指定文件格式(图片格式 png, gif,jpg jpeg)的文件相关信息的列表. 如图: 代码: public class Util { /**** * 计算文件 ...

  8. C#利用浏览按钮获得文件路径和文件夹路径

    生成文件夹路径 private void btnChoose_Click(object sender, EventArgs e) {            using (OpenFileDialog ...

  9. Spring配置文件详解 – applicationContext.xml文件路径

    Spring配置文件详解 – applicationContext.xml文件路径 Java编程                 spring的配置文件applicationContext.xml的默 ...

随机推荐

  1. MEF基本概念

    基本概念: Managed Extensibility Framework 或 MEF 是一个用于创建可扩展的轻型应用程序的库,在.NET 4.0发布 Container:容器,使用Compositi ...

  2. ES6 | 关于class类 继承总结

    子类必须在constructor方法中调用super方法,否则新建实例时会报错.这是因为子类没有自己的this对象,而是继承父类的this对象,然后对其进行加工.如果不调用super方法,子类就得不到 ...

  3. bioinformaitcs的latex版本参考文献填坑

    最近实验室投bioinfomatics的刊,编辑说要把参考文献的格式改成不带方括号的,而且加点,而且只保留前三作者,之后用et al. 折腾了一下午,终于弄出来了. 首先,导言区需要添加: \make ...

  4. Codeforces 988F. Rain and Umbrellas

    解题思路:动态规划 遍历点i,如果从前一个点i-1走到这个点i不需要伞,则疲劳值不变dp[i] = dp[i-1]. 如果前一个点i-1走到这一个点i需要伞,则从前面找一把伞. 即遍历前面的每个点j, ...

  5. HttpWebRequest WebExcepton: The remote server returned an error: (407) Proxy Authentication Required.

    1. Supply the credentials of the Currently Logged on User to the Proxy object similar to this: // Be ...

  6. 推箱子小游戏《格鲁的实验室》13关 - bfs最短路径

    下载了一款推箱子小游戏,第13关的时候怎么也破不了最佳纪录(最少步数是9而我们最好的方案是10步),因为数据比较小(6*8的方阵),所以写了个BFS来找最短路. 游戏的目标是把小黄人推到黄色球,小绿人 ...

  7. K8s初探

    1. K8s概述 2. K8s的工作原理 什么是K8s 用法: 核心概念             集群 Kubernetes Master Node Pod Lable Replication Con ...

  8. vector ----- size函数注意事项

    vector 的size函数返回vector大小,返回值类型为size_type,Member type size_type is an unsigned integral type,即无符号整数: ...

  9. IFC2x3标准阅读

    参考地址:西北逍遥-IFC数据模式架构的四个概念层详解说明 1.架构图 IFC模型体系结构由四个层次构成,从下到上依次是 资源层(Resource Layer).核心层(Core Layer).交互层 ...

  10. mysql日期加减运算

    MySQL 日期类型MySQL 日期类型:日期格式.所占存储空间.日期范围 比较. 日期类型        存储空间       日期格式                 日期范围 --------- ...