Questions tagged [nsfilehandle]

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.

140 questions
52
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
  • 811
  • 2
  • 10
  • 16
37
votes
2 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,602
  • 7
  • 40
  • 67
21
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
  • 427
  • 2
  • 9
  • 19
20
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
  • 313
  • 2
  • 8
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
  • 5,618
  • 20
  • 40
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
  • 21,790
  • 4
  • 48
  • 70
11
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
  • 484
  • 3
  • 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,363
  • 1
  • 19
  • 20
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,488
  • 1
  • 25
  • 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,141
  • 2
  • 22
  • 53
6
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
  • 76,675
  • 54
  • 235
  • 299
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
5
votes
2 answers

How to read all remaining output of readInBackgroundAndNotify after NSTask has ended?

I'm invoking various command line tools via NSTask. The tools may run for several seconds, and output text constantly to stdout. Eventually, the tool will terminate on its own. My app reads its output asynchronously with…
Thomas Tempelmann
  • 9,137
  • 6
  • 60
  • 120
5
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,175
  • 2
  • 21
  • 33
1
2 3
9 10