Java File Size Get getFileSize(final String filename)

Here you can find the source of getFileSize(final String filename)

Description

GetFileSize - returns the file size

License

Open Source License

Parameter

Parameter Description
filename - file to size

Return

length of file

Declaration

public static long getFileSize(final String filename) 

Method Source Code

//package com.java2s;
/*/*from  www .  ja va 2  s .c o  m*/
 * Copyright (c) 2006 Stephan D. Cote' - All rights reserved.
 * 
 * This program and the accompanying materials are made available under the 
 * terms of the MIT License which accompanies this distribution, and is 
 * available at http://creativecommons.org/licenses/MIT/
 *
 * Contributors:
 *   Stephan D. Cote 
 *      - Initial API and implementation
 */

import java.io.File;

public class Main {
    /**
     * GetFileSize - returns the file size
     *
     * @param filename - file to size
     *
     * @return length of file
     */
    public static long getFileSize(final String filename) {
        File f;

        try {
            f = new File(filename);

            if (f.exists()) {
                return f.length();
            }
        } catch (final Exception e) {
        }

        return -1;
    }
}

Related

  1. getFileSize(File file)
  2. getFileSize(File file)
  3. getFileSize(File file)
  4. getFileSize(File file)
  5. getFileSize(File[] files)
  6. getFileSize(final String filePath)
  7. getFileSize(final String path)
  8. getFileSize(InputStream inputStream)
  9. getFileSize(int fileSize)