Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在外部设备上安装文件时检查文件是否存在_Objective C_Cocoa_Nsfilemanager - Fatal编程技术网

Objective c 在外部设备上安装文件时检查文件是否存在

Objective c 在外部设备上安装文件时检查文件是否存在,objective-c,cocoa,nsfilemanager,Objective C,Cocoa,Nsfilemanager,播放列表文件.m3u包含外部设备(本例中为USB密钥)上可用的条目,例如: 我想检查文件是否存在: NSURL *url = [NSURL URLWithString:@"/Volumes/KINGSTON/folder/mytitle.mp3"]; NSFileManager *manager = [NSFileManager defaultManager]; NSLog(@"%d",[manager fileExistsAtPath:[url absoluteString]]); //ret

播放列表文件.m3u包含外部设备(本例中为USB密钥)上可用的条目,例如:

我想检查文件是否存在:

NSURL *url = [NSURL URLWithString:@"/Volumes/KINGSTON/folder/mytitle.mp3"];
NSFileManager *manager = [NSFileManager defaultManager];
NSLog(@"%d",[manager fileExistsAtPath:[url absoluteString]]); //returns 0. I expect 1
我还尝试:

NSURL *u = [[NSURL alloc]initWithScheme:@"/Volumes" host:@"/KINGSTON" path:@"/folder/mytitle.mp3"];
NSLog(@"%d",[manager fileExistsAtPath:[u absoluteString]]); //0
NSURL *u = [[NSURL alloc]initWithScheme:@"/Volumes" host:@"/KINGSTON" path:@"/folder/mytitle.mp3"];
我做错了什么

谢谢


罗兰

在第一个示例中,您需要使用
+[NSURL fileURLWithPath:
。在你的第二个例子中,我知道你想做什么,但你只是走错了路


我假设当您有了可以直接传递到
-fileExistsAtPath:

的路径时,您会为
+NSURL fileURLWithPath:
而烦恼,在第一个示例中,您需要使用
+[NSURL fileURLWithPath:
。在你的第二个例子中,我知道你想做什么,但你只是走错了路

我想,当您拥有可以直接传递到
-fileExistsAtPath:
的路径时,您会为
NSURL
而烦恼是有原因的

该字符串不描述URL。这是一个路径名。使用
fileURLWithPath:

绝对字符串
不返回路径;它返回一个描述URL的字符串。使用路径

或者,更好的是

我还尝试:

NSURL *u = [[NSURL alloc]initWithScheme:@"/Volumes" host:@"/KINGSTON" path:@"/folder/mytitle.mp3"];
NSLog(@"%d",[manager fileExistsAtPath:[u absoluteString]]); //0
NSURL *u = [[NSURL alloc]initWithScheme:@"/Volumes" host:@"/KINGSTON" path:@"/folder/mytitle.mp3"];
/卷不是方案,/KINGSTON不是主机,/folder/mytitle.mp3是路径,但不引用任何存在的内容

文件URL的方案是
文件:
,主机通常是localhost或空字符串。文件URL的路径是文件的完整绝对路径

该字符串不描述URL。这是一个路径名。使用
fileURLWithPath:

绝对字符串
不返回路径;它返回一个描述URL的字符串。使用路径

或者,更好的是

我还尝试:

NSURL *u = [[NSURL alloc]initWithScheme:@"/Volumes" host:@"/KINGSTON" path:@"/folder/mytitle.mp3"];
NSLog(@"%d",[manager fileExistsAtPath:[u absoluteString]]); //0
NSURL *u = [[NSURL alloc]initWithScheme:@"/Volumes" host:@"/KINGSTON" path:@"/folder/mytitle.mp3"];
/卷不是方案,/KINGSTON不是主机,/folder/mytitle.mp3是路径,但不引用任何存在的内容


文件URL的方案是
文件:
,主机通常是localhost或空字符串。文件URL的路径是文件的完整绝对路径。

NSURL是苹果公司在其文档中推荐的。没有其他动机苹果在其文档中推荐NSURL。没有其他动机