Sunday, 11 June 2017

Java Tutorial : Java IO (Java File - How to check file length) ~ foundjava


Click here to watch in Youtube :
FileDemo.java
import java.io.File;

public class FileDemo
{

    public static void main(String[] args)
    {
        File file = new File("D:/work/myfile.txt");
        /*
         * Returns the length of the file denoted by this
         * abstract pathname. The return value is
         * unspecified if this pathname denotes a directory.
         * 
         * Returns: The length, in bytes, of the file
         * denoted by this abstract pathname, or 0L if the
         * file does not exist.
         */
        long length = file.length();
        System.out.println("length = " + length);
    }

}
Output
length = 36

Click the below link to download the code:

CLICK HERE

No comments:

Post a Comment