2011-05-06 55 views

回答

0

你在做什么错的是,

NSString *filePath=[[NSBundle mainBundle] pathForResource:@"%@",file_name ofType:@"txt"]; 

的而不是代码,

NSString *filePath=[[NSBundle mainBundle] pathForResource:file_name ofType:@"txt"]; 
+0

谢谢。它的工作:) – sgoldman 2011-05-06 03:13:03

+0

@sgoldman:你欢迎:) – KingofBliss 2011-05-06 03:14:22

3

你可以简单地传递变量。

NSString *filePath = [[NSBundle mainBundle] pathForResource:file_name ofType:@"txt"]; 

而且,由于要定义file_name是一个常量字符串,你不需要使用stringWithFormat:方法。你可以直接定义它。

NSString *file_name = @"Readme"; 

如果file_name变量将是自述每一次,那么它的恒定,并不需要在所有定义:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Readme" ofType:@"txt"]; 
0
NSString *file_name = @"Readme.txt"; 

NSString *name = [file_name stringByDeletingPathExtension]; 
NSString *extension = [file_name pathExtension]; 

NSString *file_path = [[NSBundle mainBundle] pathForResource:name ofType:extension]; 
0
NSString *filePath=[[NSBundle mainBundle] pathForResource:@"Readme" ofType:@"txt"]; 
相关问题