File Length() Example
Returns the length of the file denoted by this abstract pathname.
File class Length() method example. This example shows you how to use Length method.This method Returns the length of the file denoted by this abstract pathname.
Here is the code:-
/**
* @Program that Returns the length of the file denoted by this abstract
* pathname.
* Length.java
* Author:-RoseIndia Team
* Date:-30-May-2008
*/
import java.io.*;
public class Length {
public static void main(String[] args) {
File f = new File("/home/girish/Desktop/girish.txt");
if (f.exists()) {
long l = f.length();
System.out.println("The length of the file is : " + l);
} else {
System.out.println("File does not exists");
}
}
} |
Output of the Program
| The length of the file is : 45 |
|