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) All Rights Reserved.
package com.kodehelp.javaio;


 * Created by
 * 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.