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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)