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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值