|
-
Apr 17th, 2002, 06:21 AM
#1
Thread Starter
Retired VBF Adm1nistrator
Length of a file ?
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
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 17th, 2002, 06:46 AM
#2
Try using the File class and the length() method
Code:
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 
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Apr 17th, 2002, 06:48 AM
#3
Code:
File fileName = new File("c:\\autoexec.bat")
try
{
System.out.println(fileName.length());
}
catch (Exception e)
{
e.printStackTrace();
}
if i'm not mistaken
-
Apr 17th, 2002, 06:50 AM
#4
Thread Starter
Retired VBF Adm1nistrator
Thank you very much people, I can now put a nice percentage meter in my app
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 17th, 2002, 06:52 AM
#5
Thread Starter
Retired VBF Adm1nistrator
Lovely 
Code:
lenOfFile = (new File( "packet.txt" )).length();
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|