Java File Size Get getFileSize(String loc)

Here you can find the source of getFileSize(String loc)

Description

Returns the length of a file in bytes given its location.

License

LGPL

Parameter

Parameter Description
loc file location

Return

file length

Declaration

private static long getFileSize(String loc) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.io.File;

public class Main {
    /**//from   ww  w  . j  av a  2  s.c om
     * Returns the length of a file in bytes given its location.
     *
     * @param  loc  file location
     * @return  file length
     */
    private static long getFileSize(String loc) {
        File f = new File(loc);
        if (!f.exists()) {
            System.err.println("File " + loc + " does not exist");
            System.exit(1);
        }
        long leng = f.length();
        if (leng == 0) {
            System.err.println("File " + loc + " has zero length");
            System.exit(1);
        }
        return leng;
    }
}

Related

  1. getFilesize(String filepath)
  2. getFileSize(String filePath)
  3. getFileSize(String filePath)
  4. getFileSize(String fileSize)
  5. getFileSize(String fn)
  6. getFileSize(String path)
  7. getFileSize(String path)
  8. getFilesize(String path)
  9. getFileSize2(String filename)