The NSFileHandle class is an object-oriented wrapper for a file descriptor. You use file handle objects to access data associated with files, sockets, pipes, and devices. For files, you can read, write, and seek within the file. For sockets, pipes, and devices, you can use a file handle object to monitor the device and process data asynchronously.
Questions tagged [nsfilehandle]
139 questions
                    
                    54
                    
            votes
                
                11 answers
            
        How to read data from NSFileHandle line by line?
I have a text file having data as given
e.g.…
        
        Greshi Gupta
        
- 831
 - 2
 - 10
 - 16
 
                    38
                    
            votes
                
                3 answers
            
        NSFileHandle fileHandleForWritingAtPath: return null!
my iPad app has a small download facility, for which I want to append the data using an NSFileHandle. The problem is the creation call only returns null file handles. What could be the problem? Here is the three lines of code that are supposed to…
        
        Jean-Denis Muys
        
- 6,772
 - 7
 - 45
 - 71
 
                    23
                    
            votes
                
                3 answers
            
        How to properly handle NSFileHandle exceptions in Swift 2.0?
First of all, I am new to iOS and Swift and come from a background of Android/Java programming. So to me the idea of catching an exception from an attempt to write to a file is second nature, in case of lack of space, file permissions problems, or…
        
        mirage
        
- 343
 - 2
 - 8
 
                    22
                    
            votes
                
                3 answers
            
        how to write in append mode for text file
My application navigation based.  UItextView  for notes UIViewController. I am writing data  for text to file. Now i need to write in append mode , the below code i am trying but every time is writing to two time with same text data, and not…
        
        SOF
        
- 437
 - 2
 - 9
 - 19
 
                    13
                    
            votes
                
                1 answer
            
        Overwrite Data using NSFileHandle
Using an NSFileHandle, it is pretty easy to remove n number of characters from the end of the file using truncateFileAtOffset.
-(void)removeCharacters:(int)numberOfCharacters fromEndOfFile:(NSFileHandle*)fileHandle {
    unsigned long long…
        
        Casey
        
- 6,531
 - 24
 - 43
 
                    13
                    
            votes
                
                3 answers
            
        How to check for End-of-File using NSFileHandle's readabilityHandler?
I am reading data from a NSFileHandle (from a NSPipe) using a readabilityHandler block:
fileHandle.readabilityHandler = ^( NSFileHandle *handle ) {
     [self processData: [handle availableData]];
}
This works fine, I get all the data I expect fed…
        
        Sven
        
- 22,475
 - 4
 - 52
 - 71
 
                    12
                    
            votes
                
                2 answers
            
        I cannot catch the "No space left on device" exception when using NSFileHandle writedata function
I used NSFileHandle to writedata to a file.
NSFilehandle *handle = [NSFileHandle fileHandleForWritingAtPath:@"path/of/file"];
@try {
    [handle writedata:data];
} @catch (NSException *e) {
    // when exception occur, never got here 
    …
        
        Yifan Wang
        
- 504
 - 6
 - 13
 
                    8
                    
            votes
                
                2 answers
            
        Base64 Encode File Using NSData Chunks
Update 4
Per Greg's suggestion I've created one pair of image/text that shows the output from a 37k image to base64 encoded, using 100k chunks. Since the file is only 37k it's safe to say the loop only iterated once, so nothing was appended. The…
        
        frsh
        
- 103
 - 2
 - 10
 
                    8
                    
            votes
                
                1 answer
            
        NSFileHandleDataAvailableNotification files repeatedly with no new data (resulting in very high CPU usage)
I'm attempting to read data from the Standard Error of a NSTask in Cocoa using waitForDataInBackgroundAndNotify. The following code does read the stream, so it's already working partially. 
The problem I have is that sometimes the…
        
        Marco Aurélio
        
- 2,463
 - 1
 - 21
 - 21
 
                    7
                    
            votes
                
                1 answer
            
        How to detect end-of-file for FileHandle.standardInput from Terminal
I have a Swift program that reads from FileHandle.standardInput (in Objective-C, this would be +[NSFileHandle fileHandleWithStandardInput].  It should terminate reading when it hits end-of-file on the input stream, but when I run it using the…
        
        Kristopher Johnson
        
- 81,409
 - 55
 - 245
 - 302
 
                    6
                    
            votes
                
                1 answer
            
        How to use NSFileHandle's writeabilityHandler?
Starting from OS X 10.7 and iOS 5.0 NSFileHandle has two new properties: readabilityHandler and writeabilityHandler. I tried to use writeabilityHandler, but no luck. The documentation is weird, it looks like they copy-pasted description of…
        
        Davyd Geyl
        
- 4,578
 - 1
 - 28
 - 35
 
                    6
                    
            votes
                
                6 answers
            
        How to save images and recorded files in temp directory?
I want to store pictures taken from camera and video recordings from my application in a separate folder in temporary directories for a while. And as the task is being completed, they shall be going to save into the database.
How do I save pictures…
        
        alloc_iNit
        
- 5,173
 - 2
 - 26
 - 54
 
                    6
                    
            votes
                
                1 answer
            
        How can I tell when a FileHandle has nothing left to be read?
I'm trying to use a Pipe's fileHandleForReading's readabilityHandler to read both the standardOutput and standardError of a Process. However, the moment the terminationHandler is called is actually before the moment my readabilityHandler is called…
        
        Ky -
        
- 30,724
 - 51
 - 192
 - 308
 
                    6
                    
            votes
                
                1 answer
            
        NSFileHandle writeData: exception handling
This could be rather broad problem but I could not find any online resource addressing or explaining this matter.
The question is after creating NSFileHandle *writer = [NSFileHandle fileHandleForWritingAtPath:"path"] and when you use [writer…
        
        Gihan
        
- 2,476
 - 2
 - 27
 - 33
 
                    5
                    
            votes
                
                1 answer
            
        Write to NSTasks standard input after launch
I am currently trying to wrap my head around the hole NSTask, NSPipe, NSFileHandle business. So I thought I write a little tool, which can compile and run C code. I also wanted to be able to redirect my stdout and stdin to a text view.
Here is what…
        
        Janek
        
- 111
 - 1
 - 5