检索文件

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory

NSUserDomainMask, YES);

//获取关于本工程的一系列路径

NSString *documentsDirectory = [paths objectAtIndex:0];

//paths中是一个字符串数组,但往往只有第一个是期待得到的.

    filePath = [documentsDirectory 

stringByAppendingPathComponent:@"textviewcontent"];

//关于stringByAppendingPathComponent:的用法在下面有写到

[filePathretain];

NSFileManager *myFM = [NSFileManagerdefaultManager];

 

 

stringByAppendingPathComponent:

Returns a new string made by appending to the receiver a given string.

- (NSString *)stringByAppendingPathComponent:(NSString *)aString
Parameters
aString

The path component to append to the receiver.

Return Value

A new string made by appending aString to the receiver, preceded if necessary by a path separator.

Discussion

The following table illustrates the effect of this method on a variety of different paths, assuming that aString is supplied as “scratch.tiff”:

Receiver’s String Value

Resulting String

/tmp

/tmp/scratch.tiff

/tmp/

/tmp/scratch.tiff

/

/scratch.tiff

“” (an empty string)

scratch.tiff

posted on 2012-11-14 22:13  凰浴浴的CodingBlog  阅读(198)  评论(0)    收藏  举报