Showing posts with label file-io. Show all posts
Showing posts with label file-io. Show all posts

Friday, April 27, 2012

Error saving data to cache directory (iPhone)


I am trying to save images using the following code:




- (void)writeData{

if(cacheFileName==nil)
return;
if(cacheDirectoryPath==nil)
return;


if (![[NSFileManager defaultManager] fileExistsAtPath:[self filePath]]) {

NSData *imageData = UIImageJPEGRepresentation(self.image, 0.9);

NSError *writeError= nil;

BOOL didWrite = [imageData writeToFile:[self filePath] options:NSAtomicWrite error:&writeError];

if(writeError)
NSLog([writeError localizedDescription]);

if(didWrite)
NSLog(@"image saved");
else
NSLog(@"image not saved");


}
}





- (NSString *)filePath{

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cacheDirectory = [paths objectAtIndex:0];
NSString *filename = [cacheDirectory stringByAppendingPathComponent:cacheDirectoryPath];
filename = [filename stringByAppendingPathComponent:cacheFileName];
NSLog(filename);

return filename;

}

Friday, January 13, 2012

Writing huge string data to file in java, optimization options


I have a chat like desktop java swing app, where i keep getting String type data. Eventually the String variable keeps growing larger and larger.