How to get the size of a file in java?

DeeKay April 7, 2012 at 2:42 am · java.io

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");
    }
}