Download a text file from a specific location

I was wondering how to read a file from a specific location on ios.

For example, I would really like to have files with the same name that are stored in different places, for example.

Project / Files / Text / 1.txt

Project / Files / MoreText / 1.txt

Currently I can upload files, but I don’t see how to specify a specific directory. My program downloads the file no matter where it means that I can only have one text file or another file.

I tried using NSFileManager:

NSFileManager *filemanager = [NSFileManager defaultManager];

NSArray *filelist = [filemanager directoryContentsAtPath:@"Text"];

but later I realized that this actually does nothing. It just does not return any objects. I also saw the NSBundle, but did not see an example when a particular file is returned.

I need the file names to be the same for my algorithm that downloads files.

.

+5
4

, Finder. , , , . , , Xcode.

:

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Text/1" ofType:@"txt"];
    NSString *testString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
    NSLog(@"%@",testString); 

"1.txt" "".

+11

iOS , ( ) . , :

  • Finder, .
  • Xcode " ..." "".
  • " " " " .

. .

, NSBundle Class:

+ (NSArray *)pathsForResourcesOfType:(NSString *)extension inDirectory:(NSString *)bundlePath
+2

, , 1 . , xCode. , "MyDir/myFile.txt"

0

Mac OS X - , Cocoa . . Resources, :

NSString *resDir = [[NSBundle mainBundle] resourcePath];

Text :

NSString *textDir = [resDir stringByAppendingPathComponent: @"Text"];
NSArray *textFiles = [[NSFileManager defaultManager] directoryContentsAtPath: textDir];

, Xcode Resources. , , , , .app Show Package Contents.

0

All Articles