How to get the size of the file

Hi All,
I want to get the size of the file in terms of bytes. I used the following code it returns the value in long how can get it in bytes
import java.io.File;
public class ServerBackupCheck {
     public static void main(String args[]){
          File f = new File("C:/Program Files/Apache Software Foundation/Tomcat 5.5");
          System.out.println(f.isDirectory());
          System.out.println(f.getTotalSpace());
output:
true
20964163584
regards,
Maheshwaran Devaraj

if it is a folder you can use this recursive algorithm
public static long recurse(File f) throws IOException
          long bytes = 0;
          File files[] = f.listFiles();
          for(int i =0 ;i<files.length;i++)
               File file = files ;
               if(file.isFile())
                    FileInputStream fis = new FileInputStream(file);
                    byte[] by = new byte[fis.available()];
                    fis.read(by);
                    bytes = bytes + by.length;
               if(file.isDirectory())
                    bytes = bytes + recurse(file);
          return bytes;
System.out.println(recurse(f));  gives you the total bytes....
Ayberk Cansever ..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • How to get real size of the JLable with wrapped text

    Hello all,
    I have a JLable, which should display error message or some tips to the user. Text can have different length. Something like this:
    jlblText.setText("<html><body>Error. Please do this and that. </body></html>")
    view.pack();The lable is on the top of the JDialog.
    If user typed wrong data, an error message will be displayed in the lable. If the text is too long, jlable will be wrapped. JDialog should also adjust it's size, so I use pack().
    In this case nothing happens. I wanted to get the height of the component and to increase the size of the JDialog, but
    System.out.println("height = "+view.jlblText().getHeight());returns the same result all time. No matter whether the lable contains 20 lines or just some words.
    Is it possible to automatically adjust the size of the JDialog, if the size of the JLable is changed?
    In this case I can't use JScrollPane.
    Thanks in advance.

    component listener solved the problem.
    Try something like:
    label.setText(....);
    SwingUtilities.invokeLater(new Runnable()
         public void run()
              frame.pack();
    This construction didn't do the trick. I tryed to invoke this.pack() of my JDialog in a run method.
    I am still wonder, why only the component listener get the right (actual) value, and the getHeight() method called after the setText method returns the old value.

  • How can I get the size of a file with apple script

    I try to get the size of a file within an apple script. But I did not find information how to do this.

    There are two ways. I think Apple is moving toward using System Events, which is listed first.tell application "Finder"
    set myFile to selection as alias
    --this just gets a file for me to work with
    --coercing it into an alias is required for the other functions
    end tell
    tell application "System Events"
    get size of myFile
    end tell
    set myInfo to (info for myFile)
    get size of myInfo

  • I have a question about the new version of itunes. in the old version at the bottom of the sceen it display the total number of media and the size of the files. how can i get the new version to diplay this?

    in the old version at the bottom of the sceen it displayed the total number of media and the size of the files. how can i get the new version to diplay this?

    You're welcome. It was frustrating for me as well until I stumbled across "the fix"

  • How to get to know the size of the biggest file in ContentServer

    Dear colleagues!
    Does anybody knows how to get to know the size of the biggest file in the ContentServer?
    Vladimir
    Edited by: Vladimir Pavlovsky on Mar 2, 2010 11:11 AM

    Vladimir Pavlovsky wrote:>
    > Dear colleagues!
    > Does anybody knows how to get to know the size of the biggest file in the ContentServer?
    Hi Vladimir,
    I assume you want to know the size of the biggest file stored in the content server don't you?
    This information is available through the content server API layer only - so better open this question in the knowlegde management forum.
    regards,
    Lars

  • How to get the size of the blob file uploaded ?

    Hi ,
    Is there anyway to get the size of the file i have uploaded to a blob type attribute ?
    What i can see is that when we upload a file in contributor UI ,once the file is uploaded successfully and if we hover on it , it will show the filename , type and size of the uploaded file .
    From where can we get that details so that we can reuse these details in our code ?
    Thanks and Regards,
    Praveen

    A filter is a sensible solution, or you can get it in a roundabout way like this for example if you have the blobid (this is paraphrased from OpenMarket/Gator/AttributeTypes/IMAGEPICKERShowImages.jsp):
    <ics:sql sql='<%="select urldata,filevalue from MungoBlobs where id=" + ics.GetVar("blobid")%>' listname="blobdata" table="MungoBlobs" />
    <ics:listget listname="blobdata" fieldname="urldata" output="urldata" />
    <ics:setvar name="blobpath" value='<%=ics.GetProperty("cc.urlattrpath", "gator.ini", true) + ics.GetVar("urldata")%>' />
    <%
    File blobFile = new File(ics.GetVar("blobpath"));
    long length = blobFile.length();
    %>
    Phil
    Message was edited by: pgleghorn

  • How to change the size of redo file

    Deal all,
    I finish installed the db,and the size of redo file is 50m by default. I found many "checkpoint not complete" events in alert.log file.
    Now i want to change it to 100M and try to avoid the event appear again ,how can i do?

    As Sb has already correct reply that size of redo logs can not be changed. We have to create new bigger/smaller size of redo logs and then 'alter system switch logfile' to inactivate older logs. Now you can drop older logs. Redo logs are something a glass of water. We can not change the size of glass, if we wish to dring more/less water, we will take that sized glass and we will get that sized water.
    Remember to consider the multiplexing/grouping when doing any maintenance like this. And there may be archive log & backup space considerations.
    Hans @ http://dbaspot.com/oracle-server/33231-changing-redo-log-file-size.html
    Regards
    Girish Sharma

  • How can i change the size of PDF files ?

    how can i change the size of PDF files? when i convert documents in the acrobat browser it seems the files become larger then normal pdf files, this is, i compare with other files that people send to me and i realise that they are smaller than my converted files, even if they have more pages.

    A lot depends on the form of the PDF. Is it graphics, a scan of a text file, pure text, or other? What version of Acrobat are you working with.
    You can do a save as to get a WORD file, but do not expect great results. The ability to get a decent WORD file depends on what the form of PDF you are working from. If it was created from WORD with tags and all, you might get good results. If not, you might get a lot of messed up results.
    Explain what you are starting with and your ultimate goal. Also check the audit of the file (should be under PDF Optimize) to see where the file information is concentrated (text, fonts, graphics, other).

  • How do I know the size of a file

    Hi,
    Would anybody please show me how to get the size of a file. for example, I create a file like this
    FileInputStream FINPUT = new FileInputStream ("c:\\testing.prn");
    I need to know the size of FINPUT before using it but I don't know how.
    note: It is not neccessary to use FileInputStream. I can use any stream or file that allow me to check the size and read out the data from the file byte by byte.
    Thanks a lot.
    Hung

    Thank you for your responding. But, how can I read out the data? I need to read the data from the file byte by byte.
    Thanks
    Hung.

  • How to find the size of a file or folder

    How can I find the size of a file or folder?
    I am trying to determine the size of my iPhoto and Mail folder.
    It says "Size: --" under general from Get Info.

    It's working fine...
    When you ask for that info, and Finder presents those '--' dashes instead of a value, actually, Finder is calculating the value in background.
    That's something that i recently noticed and wonder why tha heck he needs to do all that work by himself, kinda re-inventing the wheel of file size value "calculus"...
    I posted some thoughts about it here: File / Folder size... How do Finder gets it?
    Will appreciate feedback about this!
    Props!

  • How to find out the size of a file?

    Hi,
    I would like to determine the size of a file from my code. How is that possible? I do not find any appropriate method in the java.io.File class.
    Any help would be very appreciated!

    java.io.File.length()
    Returns the size of the file as a long. The number corresponds to the number of bytes in the file.

  • Getting the size of a file on the application server ?

    hi,
    hi everyone !
    i' m trying to transfer a file with the function module FTP_R3_TO_SERVER...
    But for this, i need to know the size of the file i wish to transfer...
    I found out nothing about this, but if anyone have any idea, it would be really helpful...
    thnks.

    HI,
    Why don't you use a ShellScript for FTPing your file.
    You can execute it via ABAP and it will probably does the same
    but you don't have to know how big the file is.
    can think of a few:
    1) Check the F1 help on READ DATASET. It has the addition LENGTH which you should be able to use for this purpose.
    2) Call function SXPG_COMMAND_EXECUTE for command LIST_DB2DUMP. Parse the returned table. You may need to explicitly pass 'UNIX' or 'Windows NT' to the OPERATINGSYSTEM parameter.
    3) CALL 'SYSTEM' ID 'COMMAND' FIELD 'ls -l' ID 'TAB' FIELD result-sys.
    4) Disect AL11 and make use of the same C-calls
    There's probably more...
    if u r sending the data form presentation server (SAPFTP)
    use
    describe table itab line lin .
    size = lin * width of internal row
    If u r sending the data form application server
    read the data in applicaion server file in ur prg internal table and calculate as above and size of file in ftp_r3_to_server fun module
    Cheers,
    Chandra Sekhar.

  • I am shooting with a Nikon D60 on Fine Format and unable to print larger than 11x14.  I have been able to print larger pictures.  I am told iPhoto reduces the size of the file when uploaded. Is this true? If so how can I change this?  I need 16x20's

    I am shooting with a Nikon D60 on Fine Format and unable to print larger than 11x14.  I have been able to print larger pictures.  I am told iPhoto reduces the size of the file when uploaded. Is this true? If so how can I change this?  I need 16x20's

    I am shooting with a Nikon D60 on Fine Format and unable to print larger than 11x14.  I have been able to print larger pictures.  I am told iPhoto reduces the size of the file when uploaded. Is this true? If so how can I change this?  I need 16x20's

  • How to get the size of the cuurrent illustration

    Sorry, I made a mistake before this one. The questios is this: can anybody tell me how can I get the size of the current illustration, (as oposed to the page size) in points. Something like 120 points wide and 87 points High?. What function do I need to call?

    From AI Function reference (included with CS2 SDK):
    AIDocumentSetup setup;
    error = sDocument->GetDocumentSetup(&setup);
    if (error) goto processError;
    writeDocumentSetup( &setup );
    The AIDocumentSetup record returns the following information:
    typedef struct {
    AIReal width, height;
    AIBoolean showPlacedImages;
    short pageView;
    AIReal outputResolution;
    AIBoolean splitLongPaths;
    AIBoolean useDefaultScreen;
    AIBoolean compatibleGradients;
    AIBoolean printTiles;
    AIBoolean tileFullPages;
    } AIDocumentSetup;

  • How to get the size of the webpage?

    I am designing a program to
    analyse the webpage content.
    wondering how to get the size of
    the webpage including its image's
    size and etc. Thanks in advance.

    As i know , the getContentLength just return
    then number of characters of its HTML code.
    By knowing the length of the HTML code, is
    not possible for me to calculate its download
    time... i wonder is there any way to get the
    total size of the page including its image size,
    applet size, and etc... Thanks : )

Maybe you are looking for