Iphone document Image Storage and reading,
Save: Java code
- // Specify the image access path (written to the application sandbox by default)
- NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES );
- // Give the file a file name
- NSString * uniquePath = [[paths objectAtIndex: 0] stringByAppendingPathComponent: @ "pin.png"];
- BOOL blHave = [[NSFileManager defaultManager] fileExistsAtPath: uniquePath];
- If (blHave ){
- NSLog (@ "already have ");
- Return;
- }
- // The method is to write the image to the Documents file. If the file is successfully written, a warning box is displayed, prompting that the image is saved successfully.
- NSString * strPathOld = [[NSBundle mainBundle] pathForResource: @ "pin" ofType: @ "png"];
- NSData * data = [NSData dataWithContentsOfFile: strPathOld];
- BOOL result = [data writeToFile: uniquePath atomically: YES];
- If (result ){
- NSLog (@ "success ");
- } Else {
- NSLog (@ "no success ");
- }
Java code
- NSFileManager * fileManager = [NSFileManager defaultManager];
- NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES );
- NSString * documentsDirectory = [paths objectAtIndex: 0];
- NSString * filePath2 = [documentsDirectory stringByAppendingPathComponent: @ "pin.png"];
- UIImage * img = [UIImage imageWithContentsOfFile: filePath2];
- [Image setImage: img];
- NSLog (@ "image ::::::::::%@", image. image );
Delete: Java code
- NSFileManager * fileManager = [NSFileManager defaultManager];
- NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES );
- // File name
- NSString * uniquePath = [[paths objectAtIndex: 0] stringByAppendingPathComponent: @ "pin.png"];
- BOOL blHave = [[NSFileManager defaultManager] fileExistsAtPath: uniquePath];
- If (! BlHave ){
- NSLog (@ "no have ");
- Return;
- } Else {
- NSLog (@ "have ");
- BOOL blDele = [fileManager removeItemAtPath: uniquePath error: nil];
- If (blDele ){
- NSLog (@ "dele success ");
- } Else {
- NSLog (@ "dele fail ");
- }
- }