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的默 ...
随机推荐
- WinForm关于listview的用法介绍
public Form1() { InitializeComponent(); //控件的行为 listView1.Bounds = , ), , ));//相对位置 listView1.View = ...
- 中文版 Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks
Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks 摘要 最先进的目标检测网络依靠区域提出算法 ...
- IEEE的论文需要注意的一些
详细看最近的IEEE会议模板的时候,忽然注意到表的注序号应该用字母:另外,引用未发表的论文,如果是archive上的要使用archive规定的方法,或者标注``unpublished''
- 使用python进行分页操作
class getPage: """通过这个类 获取 开始和结束点""" def __init__(self,page): try: sel ...
- swift语言点评十二-Subscripts
Classes, structures, and enumerations can define subscripts, which are shortcuts for accessing the m ...
- Calling convention-调用约定
In computer science, a calling convention is an implementation-level (low-level) scheme for how subr ...
- (转)Java 虚拟机体系结构
来源:http://hxraid.iteye.com/blog/676235 众所周知,Java源代码被编译器编译成class文件.而并不是底层操作系统可以直接执行的二进制指令(比如Windows O ...
- Iterator(迭代器) 和generator
数组是可迭代的 var a = []; console.dir(a); 发现这里有一个Symbol.iterator ,说明它是可迭代的. object 是不可以迭代的 var a = {} cons ...
- Laravel关联模型中过滤结果为空的结果集(has和with区别)
首先看代码: $userCoupons = UserCoupons::with(['coupon' => function($query) use($groupId){ return $quer ...
- 题解 洛谷 P3381 【【模板】最小费用最大流】
发了网络流,再来一发费用流 能做费用流的,网络流自然做得来,但在这还是不要脸的安利一下自己的博客(里面也有网络流的题解): 点我 扯远了... 费用流,就是在不炸水管的情况下求源点到汇点的最小费用. ...