2012-10-02 140 views
0

我正在構建一個應用程序來檢查csv文件的內容。我能夠正確檢查行和列。現在,我想知道整個文件是否爲空。檢查文件是否爲空?

回答

4

如果「空」你的意思是它在它(0字節)絕對沒有,你可以做這樣的事情:

NSFileManager *manager = [NSFileManager defaultManager]; 
if ([manager fileExistsAtPath:path]) { 
    NSDictionary *attributes = [manager attributesOfItemAtPath:path error:nil]; 
    unsigned long long size = [attributes fileSize]; 
    if (attributes && size == 0) { 
     // file exists, but is empty. 
    } 
} 
+0

什麼是路徑變量在這裏? – dcprog

+0

您的文件的路徑。 – DrummerB