Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a method in Java that takes in a List <File> Computes its size in megabyte

ID: 3792727 • Letter: W

Question

Write a method in Java that takes in a List <File> Computes its size in megabytes and returns true if the size is greater than 55mb.
Example signature:
boolean sizeCheck(List <File> files) Write a method in Java that takes in a List <File> Computes its size in megabytes and returns true if the size is greater than 55mb.
Example signature:
boolean sizeCheck(List <File> files) Computes its size in megabytes and returns true if the size is greater than 55mb.
Example signature:
boolean sizeCheck(List <File> files)

Explanation / Answer

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class FileSizeDemo {

   public static void main(String[] args) {
       List<String> files = new ArrayList<String>();
       files.add("words.txt");
       files.add("sample.txt");
       for (String filename : files) {
           File file = new File("D:\" + filename);

           if (file.exists()) {

               double bytesoccupied = file.length();
               double kb = (bytesoccupied / 1024);
               double mb = (kb / 1024);
               double gb = (mb / 1024);
               double tb = (gb / 1024);
               double pb = (tb / 1024);
               double exabyte = (pb / 1024);
               double zettab = (exabyte / 1024);
               double yottab = (zettab / 1024);

               System.out.println("the file" + filename + " occupied bytes : "
                       + bytesoccupied);
               System.out.println("kilobytes occupied in memory : " + kb);
               System.out.println("megabytes occupied in memory: " + mb);
               System.out.println("gigabytes occupied in memory: " + gb);
               System.out.println("terabytes occupied in memory: " + tb);
               System.out.println("petabytes occupied in memory: " + pb);
               System.out.println("exabytes occupied in memory: " + exabyte);
               System.out.println("zettabytes occupied in memory : " + zettab);
               System.out.println("yottabytes occupied in memory: " + yottab);
           } else {
               System.out.println("the file in the list not exists!");
           }

       }

   }

}

words.txt

dhgjlh
dgjgkhl
dfgjflkhjk
dfghkflh
fsdgdhklm
fdghklmj
sdfgdhlkgg

output

the filekoti.txt occupied bytes : 70.0
kilobytes : 0.068359375
megabytes : 6.67572021484375E-5
gigabytes : 6.51925802230835E-8
terabytes : 6.366462912410498E-11
petabytes : 6.217248937900877E-14
exabytes : 6.071532165918825E-17
zettabytes : 5.929230630780102E-20
yottabytes : 5.790264287871194E-23
File does not exists!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote