This sample helps you to find the size of a file in KiloBytes.
Here I am pushing a video file on to the device using this method and trying to find it’s size.
Make sure you give the exact file name because file name is case sensitive and push the file only in the sdcard directory in the FileExplorer.
Here is the code.

package pack.coderzheaven;


import android.os.Bundle;
import android.widget.TextView;

public class VideoLengthDemo extends Activity {
    public void onCreate(Bundle savedInstanceState) {

             File file = new File("/sdcard/my_video.mp4");
             long length = file.length();
             length = length/1024;
             System.out.println("File Path : " + file.getPath() + ", File size : " + length +" KB");
        }catch(Exception e){
        	System.out.println("File not found : " + e.getMessage() + e);

Check the LogCat for the output.


Leave a Reply

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




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.