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