Finds the size of a file.
Finds the size of a file.
The length method of file class can be used for finding the size of a file. If the file object represents a directory the length method returns zero.
package io;
import java.io.File;
public class FileExample {
public static void main(String[] args){
File file = new File("d:\\temp\\test.txt");
// Find the size of the file in bytes
long value = file.length();
// Convert the size in bytes to mega bytes.
double sizeInMB =(double) value / 1024 / 1024;
System.out.println(sizeInMB);
}
}
Tags: File, file class examples, File examples, java.io, java.io.File
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply