Results 1 to 5 of 5

Thread: Length of a file ?

  1. #1

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    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]

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  3. #3
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    Code:
    File fileName = new File("c:\\autoexec.bat")
    try
    {
      System.out.println(fileName.length());
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }

    if i'm not mistaken

  4. #4

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Thank you very much people, I can now put a nice percentage meter in my app
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  5. #5

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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
  •  



Click Here to Expand Forum to Full Width