file length Example
file class length example. This example shows you how to use length method.
File class length example. method returns long values for length of data contained in the specified abstract pathname file.method is being called by a long type variable.In case of directory pathnames an unspecified long value is returned.for media files it returns zero as no character stream data will found for measuring length.
Here is the code:-
/**
* @Program uses length method to count data length of the abstract
* pathname file.
* Length.java
* Author:-RoseIndia Team
* Date:-30-june-2008
*/
import java.io.*;
public class Length {
public static void main(String args[]) {
File data = new File("/home/mahendra/Desktop/docs.txt"), data1 = new File(
"/home/mahendra/Desktop/docs"), data2 = new File(
"/home/mahendra/Desktop/rose.wmv");
long length = data.length(), length1 = data1.length(), length2 = data2
.length();
System.out.println("'.length()' generated results");
System.out.println("'docs.txt': " + length + "\n" + "'docs': "
+ length1 + "\n" + "'rose.wmv': " + length2);
}
} |
Output of the program:-
'.length()' generated results
'docs.txt': 221
'docs': 4096
'rose.wmv': 0 |
|