Here you can find the source of getFileSize(String path)
Parameter | Description |
---|---|
path | the path to the file. |
public static long getFileSize(String path)
//package com.java2s; /**/*from w w w.j a va2s.co m*/ * * This file is part of Stuffed. * * Stuffed is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Stuffed is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Stuffed. If not, see <http://www.gnu.org/licenses/>. * * File name: Common.java * Package: cs.man.ac.uk.common * Created: May 1, 2013 * Author: Rob Lyon * * Contact: rob@scienceguyrob.com or robert.lyon@postgrad.manchester.ac.uk * Web: <http://www.scienceguyrob.com> or <http://www.cs.manchester.ac.uk> * or <http://www.jb.man.ac.uk> */ import java.io.File; public class Main { /** * Returns the size of the specified file in bytes. * @param path the path to the file. * @return the size of the file in bytes. */ public static long getFileSize(String path) { try { File file = new File(path); long fileSize = file.length(); return fileSize; } catch (Exception e) { System.out.println("Could not obtain file size:\n" + e.toString()); return -1; } } }