Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 20-06-2009
Member
 
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???
Reply With Quote
  #2  
Old 20-06-2009
Member
 
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!
Reply With Quote
  #3  
Old 20-06-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
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
Reply With Quote
  #4  
Old 20-06-2009
Member
 
Join Date: May 2008
Posts: 2,293
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");
}
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to get file size in Java"
Thread Thread Starter Forum Replies Last Post
How can I reduce size of PST file? Betelgeuse Windows Software 6 30-09-2013 11:59 AM
Reducing the PDF file size Aaghaz Portable Devices 4 25-12-2010 07:59 PM
Windows Batch file to output directory names and size to txt file m2thearkus Software Development 6 16-07-2010 12:04 AM
How To Increase Heap Size In Java Linoo Software Development 5 16-02-2010 06:33 PM


All times are GMT +5.5. The time now is 01:06 AM.