How to make memory use minimal and most efficient when iOS optimizes copying large files

Source: Internet
Author: User

I also struggle for a few days, I want to think of a way, but the data can not be copied up, I do not understand, if someone knows where I was wrong, please leave a message, if there is a better way, please share common progress.

________________________________________ copying files with an input stream

This is the path to my original picture.

NSString *path=[nshomedirectory () stringbyappendingpathcomponent:@ "2238-110h514215143.jpg"];

Nserror *error;

This is the path where I want to copy the picture.

NSString *path1=[nshomedirectory () stringbyappendingpathcomponent:@ "movies/2238-110h514215143oooo.jpg"];

NSLog (@ "%@", Path1);

Create a File object

Nsfilemanager *filemanager=[nsfilemanager Defaultmanager];

Create an empty file ready to write to the data

BOOL Success=[filemanager createfileatpath:path1 Contents:nil Attributes:nil];

if (success) {

NSLog (@ "Copy file succeeded");

}

Gets the properties of the copied file all

Nsdictionary *dictionary=[filemanager Attributesofitematpath:path error:&error];

Get the size of a file

NSNumber *number=[dictionary Objectforkey:nsfilesize];

Long long a=[number longlongvalue];

Preparing for reading and writing

Nsfilehandle *filehandle=[nsfilehandle Filehandleforreadingatpath:path];

Nsfilehandle *filehandle=[nsfilehandle Filehandleforwritingatpath:path1];

Nsmutabledata *data1;

How to implement Read 5000 byte write 5000 bytes

For (long long l=0; l<=a;) {

for (int i=0; i<=5000;i++) {

NSData *data2=[filehandle Readdataoflength:l]; That's what I'm thinking, but it's not working.

[Data1 APPENDDATA:DATA2];

l++;

//        }

[FileHandle writedata:data1];

//        }

while (a) {

NSData *data;

if (a<5000) {

If the file is less than 5000 bytes is copied directly

Data=[filehandle Readdatatoendoffile];

[FileHandle Writedata:data];

}else{

This is read from beginning to end 5000 bytes

Data=[filehandle readdataoflength:5000];

[FileHandle Writedata:data];

A minus is 5000 bytes from the beginning, which is exactly what's left when a is 0.

a-=5000;

}

}

[FileHandle CloseFile];

[FileHandle CloseFile];

return 0;

}

}

How to make memory use minimal and most efficient when iOS optimizes copying large files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.