有沒有辦法在Objective-C中執行文件處理?我只是想做簡單的讀寫,可以使用'c',但我強迫使用Objective-C類:@。我正在研究NSInputStream,但它已經過去了。有沒有解釋如何使用NSInputStream的任何教程?目標文件處理C
目標文件處理C
回答
如果你需要做的是真的簡單的I/O,你可以直接告訴一個對象從初始化自身,或本身寫入,文件系統路徑或URL。這適用於幾個基礎類,包括NSString,NSData,NSArray和NSDictionary等。
嘗試通過查看以下兩種NSString的方法開始了:
謝謝你,這真的很有幫助。 – itsaboutcode 2010-09-11 21:08:44
不客氣,我喜歡基金會的框架和其他原因。:-) – jlehr 2010-09-11 21:36:36
我發現蘋果的指南很簡短並且重點突出。 http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Streams/Articles/ReadingInputStreams.html
我也讀過這最後30分鐘,但它並沒有幫助我:( – itsaboutcode 2010-09-11 20:46:37
我有基本的文件麻煩的i/o當我第一次打它的OBJ-C以及。我結束了使用NSFileHandle獲取C風格訪問我的文件。這裏有一個基本的例子:
// note: myFilename is an NSString containing the full path to the file
// create the file
NSFileManager *fManager = [[NSFileManager alloc] init];
if ([fManager createFileAtPath:myFilename contents:nil attributes:nil] != YES) {
NSLog(@"Failed to create file: %@", myFilename);
}
[fManager release]; fManager = nil;
// open the file for updating
NSFileHandle *myFile = [NSFileHandle fileHandleForUpdatingAtPath:myFilename];
if (myFile == nil) {
NSLog(@"Failed to open file for updating: %@", myFilename);
}
// truncate the file so it is guaranteed to be empty
[myFile truncateFileAtOffset:0];
// note: rawData is an NSData object
// write data to a file
[myFile writeData:rawData];
// close the file handle
[myFile closeFile]; myFile = nil;
正是我需要的,謝謝! – Kalle 2013-12-15 05:03:28
- 1. XCode,標準C++和ifstream文件處理
- 2. C++處理文件
- 3. 文件處理C++
- 4. C++文件處理
- 5. 目標C代理的頭文件
- 6. 用目標C輪到處理玩家
- 7. 用標準文件處理
- 8. 錯誤處理vs目標c中的異常處理
- 9. C中的文件處理
- 10. c#文件處理問題
- 11. C++ BST和文件處理
- 12. C#處理文件/字節
- 13. C - 文件處理和EOF
- 14. C++文件處理問題
- 15. c中的文件處理?
- 16. C文件處理問題
- 17. 錯誤文件處理C++
- 18. C++文件處理(結構)
- 19. 預處理宏值到目標C字符串文字
- 20. 麻煩處理JQuery事件目標
- 21. 如何製作批處理文件,將另一個批處理文件放到目標文件夾
- 22. 甲骨文PRO * C:取處理光標
- 23. 目標文件組織c
- 24. 編輯文件,目標C
- 25. 從目標C文件
- 26. 寫入文件 - 目標C
- 27. 在C中處理大文本文件#
- 28. C#多文本文件處理
- 29. Cygwin始終處理目標
- 30. 批處理文件清理垃圾文件的Unity目錄
Objective-C是C的一個嚴格的超集。如果你願意,你可以在C中執行文件I/O。 – mipadi 2010-09-11 20:49:23