开发者

download file through coding

I would like to save a file in my application which I have created with code:

NSArray *arrayPathsForImg =
  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                      NSUserDomainMask,
                                      YES);

NSString *pathForImg = [arrayPathsForImg objectAtIndex:0];
pathForImg = [pathForImg stringByAppendingPathComponent:@"a.txt"];
[self.importUrlData writeToFile:pathForImg atomically:YES];

Now I want to down开发者_运维问答load it to my iPhone?


If you meant "read" the file:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"a.txt"];

And now use a initWithContentsOfFile: method. For example I used the code above to read from a property list and used the following code to get the data into a NSDictionary:

NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:filePath];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜