views:

80

answers:

2

I'm using:

NSData *output1 = [NSData dataWithContentsOfFile:@"~/centralUtilOut.tmp"];
NSString *output = [[NSString alloc]initWithData:output1 encoding:NSUTF8StringEncoding];

NSLog(@"%@", output);
[output release];

But nothing is in the debug window.

This is in objective C.

Note: centralUtilOut.tmp is a normal text file

+1  A: 

That tilde in the path makes me think your file path might not be getting handled properly. Take a look at NSString's -stringByExpandingTildeInPath method to expand the path to the full, absolute path.

For example: NSData *output1 = [NSData dataWithContentsOfFile:[@"~/centralUtilOut.tmp" stringByExpandingTildeInPath]];

Collin Allen
+2  A: 

The problem is in the path specification.

It seems that the NSData -dataWithContentsOfFile: does not expant ~.

It works when you put full path.

Or expand tilde in path:

NSData *output1 = [NSData dataWithContentsOfFile:
                      [@"~/centralUtilOut.tmp" stringByExpandingTildeInPath]];
NSString *output = [[NSString alloc]initWithData:output1 
                                        encoding:NSUTF8StringEncoding];

NSLog(@"%@", output);
[output release];
stefanB
Then how would i get the full home dir path using ~ ?
Daniel
Try with `stringByExpandingTildeInPath`, see doc http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/stringByExpandingTildeInPath
stefanB