1 void copyFile()
2 {
3 NSString *home=NSHomeDirectory();
4 NSString *path=[NSString stringWithFormat:@"%@/desktop/oc.mp4",home];
5 NSString *path1=[NSString stringWithFormat:@"%@/desktop/oc1.mp4",home];
6 NSFileHandle *handle=[NSFileHandle fileHandleForReadingAtPath:path];
7 NSFileManager *fm=[NSFileManager defaultManager];
8 BOOL ret=NO;
9 if ([fm fileExistsAtPath:path1])
10 {
11 NSLog(@"存在");
12 }
13 else
14 {
15 ret= [fm createFileAtPath:path1 contents:nil attributes:nil];
16
17 }
18 NSFileHandle *writeHandle=[NSFileHandle fileHandleForWritingAtPath:path1];
19 NSData *data=nil;
20 if (ret==YES)
21 {
22 data=[handle readDataOfLength:1024*1024];
23 while ([data length]==1024*1024)
24 {
25 [writeHandle writeData:data];
26 data=[handle readDataOfLength:1024*1024];
27 }
28 [writeHandle writeData:data];
29 }
30 [handle closeFile];
31 [writeHandle closeFile];
32
33 }
时间: 2024-11-04 02:27:54