To capture the file size of file.

Requirement:- There is a requirement to capture the file size of files that are picked from file source.


Solution:- In this below code, change the filename location to the location where the file is placed:-


        String fileName = "C:/Users/Desktop/test.txt";

        File f = new File(fileName);
        long fileSize = f.length();

      context.put("FileSize", fileSize);

The file size will be displayed in the variable "FileSize". Also, this value will be shown in context info too.

Have more questions? Submit a request


Article is closed for comments.