Results 1 to 4 of 4

Thread: How to get file size in Java

  1. #1
    Join Date
    Mar 2009
    Posts
    32

    How to get file size in Java

    I was trying to build the program which tells me the exact size of that file, but i was not getting it. Example: if i give the path of the image file of 64kb, it should return me the value 64kb. Can anyone provide me the code here please???

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to get file size in Java

    to get the size of a file :

    Code:
        File file = new File("infilename");
        long length = file.length();
    Hope this Helps!

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to get file size in Java

    Read The Docs there is a method on it! To read Doc follow the link below :

    DOCUMENT

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: How to get file size in Java

    I have written the following code. Just run it & give the Path of the file in the input box it will give you the output in kb.

    Code:
    import java.io.;
    import javax.swing.;
    public class FileSizeTest
    {
    public static void main(String args[])
    {
    String file = JOptionPane.showInputDialog("File Path and Name, please type like C:\\directoyname\\filename");
    File f=new File(file);
    long size=f.length()/1000;
    
    System.out.println(size"KB");
    }
    }

Similar Threads

  1. How can I reduce size of PST file?
    By Betelgeuse in forum Windows Software
    Replies: 6
    Last Post: 30-09-2013, 11:59 AM
  2. Reducing the PDF file size
    By Aaghaz in forum Portable Devices
    Replies: 4
    Last Post: 25-12-2010, 07:59 PM
  3. Windows Batch file to output directory names and size to txt file
    By m2thearkus in forum Software Development
    Replies: 6
    Last Post: 16-07-2010, 12:04 AM
  4. How To Increase Heap Size In Java
    By Linoo in forum Software Development
    Replies: 5
    Last Post: 16-02-2010, 06:33 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,927,071.87969 seconds with 17 queries