How to get the size of a file in java?

Below java code shows how to get the size of a file in bytes –

/****************************************************************************************
 * Created on 04-2012 Copyright(c) http://kodehelp.com All Rights Reserved.
 ****************************************************************************************/
package com.kodehelp.javaio;

import java.io.File;

/**
 * Created by http://kodehelp.com
 * Date: 4/6/12
 */
public class GetFileSize {
    public static void main(String args[]){
        File file = new File("/sample.log");
        long filelength = file.length();
        System.out.println("Size of your file is:"+ filelength +" Bytes");
    }
}

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.