gpt4 book ai didi

ios - 在stringWithContentsOfFile期间记录错误消息

转载 作者:行者123 更新时间:2023-12-01 19:11:47 24 4
gpt4 key购买 nike

我正在尝试读取CSV文件。我已经在应用程序中导入了文件,因此该文件位于本地。当我执行下面这部分代码时:

@autoreleasepool {
NSError *error;
NSString *alldata = [NSString stringWithContentsOfFile:@"config_menu_position.csv"
encoding:NSUTF16StringEncoding error:&error];
NSLog(@"alldata: %@", alldata);
NSLog( @"error: %@", error );
}

我有此日志错误消息,并且我的变量始终为nul:
    2013-04-21 17:05:37.571 PageViewController[1578:c07] alldata :(null)
2013-04-21 17:05:38.242 PageViewController[1578:c07] error: Error Domain=NSCocoaErrorDomain
Code=260 "The operation couldn’t be completed. (Cocoa error 260.)" UserInfo=0x7ebf100
{NSFilePath=config_menu_position.csv, NSUnderlyingError=0x7ebf060 "The operation couldn’t be
completed. No such file or directory"}

任何的想法?

最佳答案

您缺少文件的完整路径,请尝试以下操作:

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"config_menu_position" ofType:@"csv"];
NSString *alldata = [NSString stringWithContentsOfFile:filePath
encoding:NSUTF16StringEncoding
error:&error];

关于ios - 在stringWithContentsOfFile期间记录错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16132634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com