hyg0406 2014-12-02 08:05 采纳率: 0%
浏览 2204

ios开发中,运用nsfilehander写文件时报错,本人菜鸟,请教大神

NSString *path = NSHomeDirectory();

NSString *filePath = [path stringByAppendingString:@"/test.txt"];

BOOL success =[[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil];

if (success) {
NSLog(@"创建成功");
}

NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:filePath];

NSArray *array = [NSArray arrayWithObjects:@"a",@"b",@"c", nil];

for (int i=0;i<3; i++) {
data = [array objectAtIndex:i] ;

[fileHandle writeData:data  ];

}

[fileHandle closeFile];

报错代码:
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString enumerateByteRangesUsingBlock:]: unrecognized selector sent to instance 0x6c090'

*** First throw call stack:
(
0 CoreFoundation 0x008bedf6 exceptionPreprocess + 182
1 libobjc.A.dylib 0x00548a97 objc_exception_throw + 44
2 CoreFoundation 0x008c6a75 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x0080f9c7 ___forwarding
_ + 1047
4 CoreFoundation 0x0080f58e CF_forwarding_prep_0 + 14
5 Foundation 0x001597c9 -[NSConcreteFileHandle writeData:] + 142
6 联系人管理 0x00069877 -[ViewController viewDidLoad] + 487
7 UIKit 0x00dc6d54 -[UIViewController loadViewIfRequired] + 771
8 UIKit 0x00dc7045 -[UIViewController view] + 35
9 UIKit 0x00cbed65 -[UIWindow addRootViewControllerViewIfPossible] + 66
10 UIKit 0x00cbf1dc -[UIWindow _setHidden:forced:] + 319
11 UIKit 0x00cbf473 -[UIWindow _orderFrontWithoutMakingKey] + 49
12 UIKit 0x00ccd615 -[UIWindow makeKeyAndVisible] + 80
13 UIKit 0x00c6acd6 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3108
14 UIKit 0x00c6e16d -[UIApplication _runWithMainScene:transitionContext:completion:] + 1639
15 UIKit 0x00c86d30 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke + 59
16 UIKit 0x00c6cd7f -[UIApplication workspaceDidEndTransaction:] + 155
17 FrontBoardServices 0x031f59de __37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 71
18 FrontBoardServices 0x031f546f __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54
19 FrontBoardServices 0x03207425 __31-[FBSSerialQueue performAsync:]_block_invoke + 26
20 CoreFoundation 0x007e27a0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK
_ + 16
21 CoreFoundation 0x007d80b3 __CFRunLoopDoBlocks + 195
22 CoreFoundation 0x007d7f0b __CFRunLoopRun + 2715
23 CoreFoundation 0x007d71ab CFRunLoopRunSpecific + 443
24 CoreFoundation 0x007d6fdb CFRunLoopRunInMode + 123
25 UIKit 0x00c6c744 -[UIApplication _run] + 571
26 UIKit 0x00c6fe16 UIApplicationMain + 1526
27 联系人管理 0x0006aa8d main + 141
28 libdyld.dylib 0x02c0cac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

  • 写回答

1条回答

  • Jason战神 2014-12-02 09:20
    关注

    顶起来,我也想知道这个问题

    评论

报告相同问题?

悬赏问题

  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)