Click to See Complete Forum and Search --> : Length of a file ?
plenderj
Apr 17th, 2002, 07:21 AM
Just wondering, is there a way of finding out the length of a file without actually reading through until the end of the file ?
Using just pure jdk, so no wfc java stuff
crptcblade
Apr 17th, 2002, 07:46 AM
Try using the File class and the length() method
import java.io.*;
class Test
{
public static void main(String[] args)
{
try
{
File f = new File("C:\\test.txt");
if (f.exists()) System.out.println(f.length()); //Length of the file in bytes
}
catch(Exception e){}
}
}
Oh, and...WFC?? You've gotta be kidding :p
:)
axion_sa
Apr 17th, 2002, 07:48 AM
File fileName = new File("c:\\autoexec.bat")
try
{
System.out.println(fileName.length());
}
catch (Exception e)
{
e.printStackTrace();
}
if i'm not mistaken :confused: :p
plenderj
Apr 17th, 2002, 07:50 AM
Thank you very much people, I can now put a nice percentage meter in my app :)
plenderj
Apr 17th, 2002, 07:52 AM
Lovely :)
lenOfFile = (new File( "packet.txt" )).length();
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.