创建一个目录info,并在目录中创建一个文件test.txt,把该文件的信息读取出来,并显示出来

时间:2023-01-02 23:36:23

/*4.创建一个目录info,并在目录中创建一个文件test.txt,把该文件的信息读取出来,并显示出来*/

#import <Foundation/Foundation.h>
#define PATH @"/Users/qianfeng/Desktop/hehe/info"
#define PATH1 @"/Users/qianfeng/Desktop/hehe/info/test.txt"
int main(int argc, const char * argv[]) {
    @autoreleasepool {
        
        NSFileManager *mana = [NSFileManager defaultManager];
        BOOL j = [mana createDirectoryAtPath:PATH withIntermediateDirectories:YES attributes:nil error:nil];
        NSLog(@"%d",j);
        BOOL i = [mana createFileAtPath:PATH1 contents:[@"welcome to dalian" dataUsingEncoding:4]  attributes:nil];
        NSLog(@"%d",i);
        
        NSFileHandle *filehandle = [NSFileHandle fileHandleForReadingAtPath:PATH1];
        NSData *data = [filehandle readDataToEndOfFile];
        
       // NSLog(@"%s",data.bytes);
        NSString *str = [[NSString alloc]initWithData:data encoding:4];
        NSLog(@"%@",str);
        
    }
    return 0;
}