I'm trying to find a file size. But my length is equl to zero
Asked Answered
A

2

1

I'm trying to find a file size.

 NSFileHandle *output = [NSFileHandle fileHandleForWritingAtPath:self.finalPath]; 
//seek to begin of the file
[output seekToFileOffset:0];
NSData *mydata = [output availableData];
NSLog(@"length: %d", [mydata length]);

But my length is equl to zero. Why?

Animality answered 28/2, 2012 at 9:58 Comment(0)
F
11

availableData is for reading files. If you just want to find out the size of a file, you don't actually have to open it. Just use NSFileManager like this:

NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:self.finalPath error:NULL];
unsigned long long fileSize = [attributes fileSize]; // in bytes
Flan answered 28/2, 2012 at 10:3 Comment(0)
A
2

[fileHandler seekToEndOfFile], this returns the length of your file data, your code [output seekToFileOffset:0] means from 0-0,so there is no data

Apologize answered 24/6, 2014 at 12:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.