ios - 在应用程序的主目录中保存文件
问题描述
App.app/here.text 下的 txt 文件?目前我发现NSSearchPathForDirectoriesInDomains
NSArray* dirs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] error:NULL];
但它放在文件下。我可以将它保存在 Appname.app/here 下吗
https://www.alphansotech.com/wp-content/uploads/2015/11/iosDirectory.png
我可以在什么级别列出读取的文件?/private/var/containers/Bundle/Application/EF4585FC-743D-409D-83A9-B8A298D44C74/App.app
NSString * path = [[NSBundle mainBundle] resourcePath];
[path stringByDeletingLastPathComponent];
NSArray* dirs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[path stringByDeletingLastPathComponent] error:NULL];
NSLog(@"sss..%@",path );
NSLog(@"sss..%@",[path stringByDeletingLastPathComponent]);
NSString *stringToWrite = @"1\n2\n3\n4";
NSString *filePath = [path stringByAppendingPathComponent:@"main.jsbundle"];
[stringToWrite writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
[dirs enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSLog(@"sss...%@", obj);
}];
解决方案
长话短说:
不,你不能。由于显而易见的原因,不可能写入应用程序包。
推荐阅读
- r - 如何合并数据集,然后创建一个包含两条线和一个辅助轴的折线图?
- android - 停止重叠 Android 音频通知
- python - Django shell_plus:如何在 Docker 容器中访问 Jupyter 笔记本
- websphere - 我可以在 ESQL 中进行 CAST 引用吗?
- node.js - 如何修复“同一连接的重复数据库对象”dynamodb 警告
- nestjs - 在nestjs服务器上发布Formdata
- reactjs - 客户使用 Paypal 付款并立即离开网站导致他没有收到商品
- xv6 - 如何在 xv6 中使用 kbgetc
- c++ - Mingw32 无法静态链接到 libgcc_s_dw2-1、libstdc++-6、libwinpthread-1 (Qt 5.7.1)
- bash - 如何替换文本文件中周期性出现的数组