NSString * path=NSHomeDirectory();
path =[path stringByAppendingPathComponent:@"deskTop/Boby.m"];
NSString * target=NSHomeDirectory();
target =[target stringByAppendingPathComponent:@"deskTop/target.m"];
NSFileManager * manager=[NSFileManager defaultManager];
//校验并且创建文件
if(![manager fileExistsAtPath:path]){
[manager createFileAtPath:path contents:nil attributes:nil];
}
if(![manager fileExistsAtPath:target]){
[manager createFileAtPath:target contents:nil attributes:nil];
}
NSDictionary * dic=[manager attributesOfItemAtPath:path error:nil];
NSFileHandle * handle=[NSFileHandle fileHandleForReadingAtPath:path];
NSFileHandle * handletTarget=[NSFileHandle fileHandleForWritingAtPath:target];
int total=(int)[dic[@"NSFileSize"] integerValue];
self.totalSize=total;
int per=50;
int count=total%per==0?total/per:total/per+1;
for(int i=0;i<count;i++){
[handle seekToFileOffset:self.nowSize];
NSData *data= [handle readDataOfLength:per];
int tem=per*(i+1);
if(tem>total){
tem=total;
}
self.nowSize=tem;
[handletTarget seekToEndOfFile];
[handletTarget writeData:data];
[NSThread sleepForTimeInterval:0.2];
}
[handle closeFile];
[handletTarget closeFile];
- (id) initWithFile:(FileMake *)files{
self=[super init];
if(self){
self.file= files;
[self.file addObserver:self forKeyPath:@"nowSize" options:NSKeyValueObservingOptionNew context:nil];
}
return self;
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
CGFloat all=self.file.totalSize;
CGFloat now=[[change objectForKey:@"new"] floatValue];
CGFloat result=now/all;
NSLog(@"%.2f",result);
//一定不能忘了销毁当前的观察者
if(result==1){
[self.file removeObserver:self forKeyPath:@"nowSize"];
}
}
- (void) begin{
[self.file startCopy];
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有