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
Object-C,文件路径API的更多相关文章
- C#常见的文件路径Api
我们经常有遇到要处理文件路径的需求,那么一般我们常见的有几种: 程序下面的文件 临时目录下的文件 获取程序下面的文件 首先我们创建了实例解决方案: 其中调用链是:Main.Shell->FooA ...
- Android用路径api在内部存储读写文件
复制并修改原有项目 复制之前创建的项目CC+CV操作 需要改动的地方: * 项目名字 * 应用包名 * R文件重新导包 接着修改件/AndroidManifest.xml中的包名:package=&q ...
- LoadLibrary文件路径及windows API相关的文件路径问题
LoadLibrary HMODULE WINAPI LoadLibrary( _In_ LPCTSTR lpFileName ); Loads the specified module into ...
- windows API实现用户选择文件路径的对话框
在编写应用程序时,有时需要用户选择某个文件,以供应用程序使用,比如在某些管理程序中需要打开某一个进程,这个时候需要弹出一个对话框来将文件路径以树形图的形式表示出来,以图形化的方式供用户选择文件路径,而 ...
- 01 语言基础+高级:1-5 常用API第二部分_day01.【Object类、常用API: Date类、System类、StringBuilder类】
day01[Object类.常用API] 主要内容 Object类 Date类 DateFormat类 Calendar类 System类 StringBuilder类 包装类 java.lang.O ...
- Spring配置文件详解 - applicationContext.xml文件路径
spring的配置文件applicationContext.xml的默认地址在WEB-INF下,只要在web.xml中加入代码 org.springframework.web.context.Cont ...
- Android根据文件路径加载指定文件
Android根据指定的文件路径加载指定文件格式(图片格式 png, gif,jpg jpeg)的文件相关信息的列表. 如图: 代码: public class Util { /**** * 计算文件 ...
- C#利用浏览按钮获得文件路径和文件夹路径
生成文件夹路径 private void btnChoose_Click(object sender, EventArgs e) { using (OpenFileDialog ...
- Spring配置文件详解 – applicationContext.xml文件路径
Spring配置文件详解 – applicationContext.xml文件路径 Java编程 spring的配置文件applicationContext.xml的默 ...
随机推荐
- quartz.net定时任务框架详解
C#做定时任务:一是Timer:而是Quartz.net:本文就学习一下Quartz.net框架 Quartz.net非常的灵活,开发人员能用很少的代码就能完成“每隔一小时执行”.“每天2点执行”.“ ...
- Django(part3)
URLConf:负责url到view的map,就是一个urls.py module,通常在project和app级别都要定义, #mysite/urls.py from django.conf.url ...
- javaEE的开发模式
1.什么是模式 模式在开发过程中总结出的“套路”,总结出的一套约定俗成的设计模式 2.javaEE经历的模式 model1模式: 技术组成:jsp+javaBean model1的弊端:随着业务复杂性 ...
- [转]C++ 获取文件夹下的所有文件名
转自http://www.cnblogs.com/fnlingnzb-learner/p/6424563.html 头文件:#include<io.h> char * filePath = ...
- [转] CentOS 7 为firewalld添加开放端口及相关资料
转自http://www.cnblogs.com/hubing/p/6058932.html 1.运行.停止.禁用firewalld 启动:# systemctl start firewalld 查 ...
- Oracle12C查询自建用户(非系统自带)
select username from dba_users where INHERITED='NO';
- appium ios端自动化测试配置
一.安装环境介绍macOS 10.12.4 Xcode 8.3.2 适用机型:iOS9 及以上机型 二.Appium源码安装Xcode升级8.2之后不再支持UIAutomation,转而使用XCUIT ...
- Linux 添加挂载硬盘(包含挂载大于2T以上硬盘)
转自:http://blog.csdn.net/season_hangzhou/article/details/36423223 由于事先规划问题或者业务需求量激增,总会出现机器硬盘空间不够用的情况 ...
- docker私有仓库yum安装 docker-registry
[root@riyimei-node1:/root]> yum install docker-registryLoaded plugins: fastestmirror, langpacksLo ...
- Vue2.0父子组件间事件派发机制
从vue1.x过来的都知道,在vue2.0中,父子组件间事件通信的$dispatch和$broadcase被移除了.官方考虑是基于组件树结构的事件流方式实在是让人难以理解,并且在组件结构扩展的过程中会 ...