ios - iPad 上的文件 I/O

标签 ios file io

专家..一个新问题

我开发了一个类似 GIS 的应用程序,它可以在 Xcode 和 iPad 模拟器环境中完美运行。现在我想在真正的 iPAD 上进行测试。我已经完成了配置证书过程,并且能够在我的设备上运行该应用程序。当程序尝试读取我的开发计算机上的文件时出现问题(文件路径类似于/Users/user/Document/data.txt)。

我可以将“data.txt”文件复制到 ipad 吗?如果可以,它的 I/O 路径是什么。

感谢您的帮助。

KAS

最佳答案

您将把它添加到您的应用程序中。它将包含在 bundle 中。

NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"data" ofType:@"txt"]];

加载后,用字符串解析。

您可以使用 NSScanner 来解析您的字符串

NSString *fileName = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"txt"];
NSError *error = nil;
NSString *myData = [NSString stringWithContentsOfFile:fileName encoding:NSASCIIStringEncoding   error:&error];
NSScanner *myScanner = [NSScanner scannerWithString:myData];
int myNewInt = 0;
if ([myScanner scanInt:&myNewInt])
{
    //Do Something with my New Int
}

关于ios - iPad 上的文件 I/O,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5864566/

相关文章:

java - 套接字异常 : Connection closed by remote host when pushing to producation destination

文件的 C++ 输出流不起作用

c++ - 使用/不使用 ios::binary 模式打开流时使用读/写的区别

c++ - 检查 istream::read 和 istream::seekg 失败的最佳方法

objective-c - API 应该为 int 参数返回 NULL 吗? + 如何处理

iphone - 在两个 ViewController 之间共享 NSArray 数据

C# - 在 USB FAST 上创建大文件

java - 数据库对象POJO中的文件(Springboot)

python - 当另一个进程仍在写入时删除文件

javascript - JS - 检测 UIwebView