Can't get file size, possibly because of charset problem

I have an application that needs to recursively find directory sizes, I have a class extending java.io.File with an internal method to do this:
private static long getSize(File file) {
                long size = file.length();
                if (file.exists()) {
                        if (file.isDirectory()) {
                                File[] files = file.listFiles();
                                for (int i = 0; i < files.length; i++) {
                                        size += getSize(files);
} else {
System.out.println("Problem checking size on \"" + file + "\", reported file size is: " + file.length());
return size;
It works (matches du -b output) with the exception of some problematic files I have.
Output from ls:
$ ls -l
total 5461
-rw-r--r--  1 xyz users    1003 Feb 16 22:06 FileWRS.class
-rw-r--r--  1 xyz users     831 Feb 16 22:04 FileWRS.java
-rw-r--r--  1 xyz users     489 Feb 16 22:07 FolderSizes.class
-rw-r--r--  1 xyz users     198 Feb 16 21:23 FolderSizes.java
-rwxrwxrwx  1 xyz users 5568138 Apr 25  2004 test.?.abcOutput from du -b:
$ du -b
5583203 .Output from my code:
$ java FolderSizes .
Problem checking size on "./test.?.abc", reported file size is: 0
15065The character displaying as "?" is actually an accented e character ("�") and displays correctly in konqueror (my gui file browser).
I don't really know why it can't pick up the character, but I'm more interested in just getting the file size and ignoring the character problem, any solutions/suggestions for places to look? Do I need to supply more information?

Try:
LC_ALL=en_US.ISO8859-1 java FolderSizes .
Does this help?Yes, that does fix it for my terminal, but if possible I would like a solution that can determine this at run time and solve (so that when it's running on some other terminal, with some other charset, with someother file system charset it will still work).
Any ideas for doing this from withing the VM?
p.s. thanks for the fast reply.

Similar Messages

  • In the metadata settings i can find the file size in pix. is it possible to see the size in inches?

    in the metadata settings i can find the file size in pix. is it possible to see the size in inches?

    Yes, that is one way to do it. But you can also do it by doing some simple math. For instance, let's say the you have an image that is 4000 x 6000 pixels. It doesn't matter whether resolution setting is in the file. The image is still 4000 x 6000 pixels. But you can decide what resolution you are going to export your copy. And you would do that for its intended purpose. If you are going for a high quality print then you would probably want 300 PPI in your export settings. With the example I've given the size print you can get had 300 PPI would be as follows:
    4000 (pixels) / 300 (PPI) = 13.333 Inches
    6000 (pixels) / 300 (PPI) = 20 inches
    So if you were really precise in needing a 300 PPI print you can get one that is 13 x 20".
    If you are preparing for display on the screen, the higher resolution isn't needed. Using the same math:
    4000 / 72 = 55.55 inches
    6000 /  72 = 83.33 inches
    By doing some simple math in your head you can determine the resolution that you need and the size that you need and set up your export accordingly.
    Technically speaking a digital image doesn't have a size other than pixel dimensions. Everything else has to be determined by the resolution that you need for the intended purpose of the final image.

  • File receiver - Get file size

    Hi all,
    In my scenario, the message mapping is such that the target message may or may not have child nodes created depending on certain conditions. I am using file receiver channel to write this target message as xml file on another server.
    The issue I am facing is - suppose child nodes are not created, the target message has only root node, and nothing else. i.e. it is empty.
    But still the file gets written on destination, because file adapter doesn't seem to have intelligence to look into the payload. So I have to manually delete such 'almost-empty' files.
    Although PI 7.0 has feature of ignoring empty files, the file I am talking of is really not of 0 kb size, as it contains namespace and root node tag. It has very small size of 1 kb, this is fixed and thus the file is easily distinguished from other larger files which contain child nodes. File size is a parameter that can be certainly used as a key here, but don't know how.
    Does anyone have any idea on -
    1) How to check file size before file receiver adapter writes it,
    2) How to prevent such file from getting written, or
    3) run a script which can detect the file size and delete them periodically / or every time file receiver writes files ?
    Regards,
    - Shankar.

    Hi,
    We have an option of empty file handling in receiver file adapter..
    <i>      Select the Handling of Empty Messages:       Write Empty File
    An empty file (length 0 bytes) is put in the target directory.
           Ignore No file is put in the target directory.</i>
    But your case namespace and root node only are available you said.
    In this type of situations ..
    We can handle in the following way..
    If target side root node having the recordset node
    root
      recordset 0..unbound
         child1 0.1
         child2   0.1
    Then create a UDF
    map from left side one node -
    exists --- UDF ---to right side root node
    In UDF
    //handle business logic and
    ....ResultList.SUPPRESS.
    if your target side does not have any recordset type of structure then..
    In messages tab change the occurrences of msg to 0..unbound and use the above UDF.
    Regards
    Chilla..

  • A column in a table has physical file path (I want to get file size of those docs from the OS)

    Experts!!
    I have a table that holds the physical file path of files in one of its columns. It does not give a link, just the physical file path.
    For example,---- C:\bu\test.pdf   and let us say the file size is kb according to the OS.
    Is there any way I can obtain the file size of the files from the physical path?
    for example, the file size of the test.pdf file in the example here using t-SQL?
    Much Appreciation
    ebro

    Hey there... thanks for the response......I found the following as a solution for my problem. But my problem is the SP created using the method needs a directory as a parameter. How can I pass the directory from a table that holds my directory?
    EXEC  [dbo].[GetListOfFileWithSize](@Dir)
    How do I pass the directory from my table?
    http://stackoverflow.com/questions/7952406/get-each-file-size-inside-a-folder-using-sql/7958070#7958070
    ebro

  • I can not get the new updates because my start disc and hard drive are full, I need 1.98 GB.

    I can not get the new updates because my start disc and hard drive are full, I need 1.98 GB.

    Some folks recommend OmniDiskSweaper to allow you to review your stuff to find possible candidates to throw away.
    Even if you throw away some stuff and your desired "1.98GB", then what?  If that's the number you need for the update, you'll just use most or all of the reclaimed space with the update and you are right back to where you started.
    You don't specify what kind of machine you got but presumably it's a mac pro since you posted in the Mac Pro community.  In which case just get yourself another drive or two and move stuff around to free up your boot drive.
    [Perhaps you should hurry too since I expect hdd prices might be going up due to possible impending hdd shortages.]
    Finally, if some of those updates are major system updates you want extra drives for backups because I always recommend you never do major updates to your system without backups to that system.

  • I can't remember my Apple ID password or my security question answers. When I try to reset my password it wants to send it to my e-mail address but I can't get the e-mail because I don't have security answers or the password. How do I reset password?

    I can't remember my Apple ID password or my security question answers. When I try to reset my password it wants to send it to my e-mail address but I can't get the e-mail because I don't know my security answers or the password. How do I reset password?

    Alternatives for Help Resetting Security Questions and/or Rescue Mail
         1. If you have a rescue email address or a Security Questions issue, then see:
             If you forgot the answers to your Apple ID security questions - Apple Support.
             Manage your Apple ID primary, rescue, alternate, and notification email addresses - Apple Support
         2. Fill out and submit this form. Select the topic, Account Security. You must
             have a Rescue Email to use this option.
         3. This is the only option if you do not already have a valid Rescue Email.
             These are telephone numbers for contacting Apple Support in your country.
             Apple ID- Contacting Apple for help with Apple ID account security. Select
             the appropriate country and call. Ask to speak to the Account Security Team.
         4. Account security issues almost always require you to speak directly to an
             Apple representative to securely establish your identity as the account holder.
             You can set it up so that Apple calls you, either immediately or at a time
             convenient to you.
                1. Go to www.apple.com/support.
                2. Choose Contact Support and click Contact Us.
                3. Choose Other Apple ID Topics and choose the appropriate topic for
                    your issue.
                4. Follow the onscreen instructions.
             Note: If you have already forgotten your security questions, then you cannot
             set up a rescue email address in order to reset them. You must set up
             the rescue email address beforehand.
    Your Apple ID: Manage My Apple ID.
                            Apple ID- All about Apple ID security questions.

  • My laptop got formatted and so did all my itunes information like music, contacts, and games. So how can I get all that back because if I just plug my iPhone into the laptop all my stuuf that was on my phone will be gone? help please

    My laptop got formatted and so did all my itunes information like music, contacts, and games. So how can I get all that back because if I just plug my iPhone into the laptop all my stuuf that was on my phone will be gone? help please

    http://www.wideanglesoftware.com/touchcopy/index.php

  • How can I get file list for a given directory?

    Hi,
    How can I get file list for a given directory? Is there a function?
    Thanks.

    Hi friend,
    Try this sample report. It displays all files in a directory.
    While executing give some directory name in input. ex:  C:\
    Mention file type in filter parameter. ex: *.DOC
    REPORT ztests.
    DATA : file_table LIKE TABLE OF sdokpath WITH HEADER LINE .
    DATA : dir_table LIKE TABLE OF sdokpath WITH HEADER LINE .
    PARAMETERS:p_dir(50) TYPE c.
    CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'
      EXPORTING
        directory  = p_dir
        filter     = '*.DOC'
      TABLES
        file_table = file_table
        dir_table  = dir_table
      EXCEPTIONS
        cntl_error = 1
        OTHERS     = 2.
    LOOP AT file_table .
      WRITE:/ file_table-pathname.
    ENDLOOP.
    Might be helpful...
    Thanks.....
    Edited by: Guest77 on Feb 11, 2009 5:30 AM

  • Upgraded to IO6, seems like the amount of system memory to run is higher, this causes issues with some Apps. I can't get SIRI to work because the amount of free system memory is not enough. how can I tell what is eating the system memory?

    Upgraded to IO6, seems like the amount of system memory to run is higher, this causes issues with some Apps. I can't get SIRI to work because the amount of free system memory is not enough. how can I tell what is eating the system memory?

    Upgraded to IO6, seems like the amount of system memory to run is higher, this causes issues with some Apps. I can't get SIRI to work because the amount of free system memory is not enough. how can I tell what is eating the system memory?

  • I can't get files to attach in e-mail quickly.

    I can't get files to attach in e-mail. I get a prompt to retry or switch and retry. Switching works but the process takes too long.

    Which email client are you using? 

  • I have a G4 Quicksilver that no longer works, but the hd may still be good. How can I get files off the G4 hd and onto my new iMac?

    I have a G4 Quicksilver 2001 that no longer works, but the hd may still be good. How can I get files off the G4 hd and onto my new late 2013 iMac?

    Also, how do I boot the G4 into FireWire Target Disk mode?
    First, the G4 must be able to start to use FWTDM. If it can start, hold the t key at boot until you get a "screensaver pattern" that looks like this:
    If the G4 is attached via a FireWire cable to a newer Mac with a FireWire port, the G4's hard drive will appear on the other Mac's desktop just as if it were any external drive. A USB cable won't work for FWTDM.
    Just wondering if the drive in my G4, which I believe may be an ATA drive will also work in an enclosure for a SATA drive?
    No. ATA (actually "PATA" or "IDE") and SATA are different interfaces. PATA external enclosures are now very hard to find. You best and least expensive option is the adaptor that BDAqua linked. One of its connectors is for PATA drives.

  • I can't get the podcast app because I don't have ios7 is there anything I can do?

    I can't get the podcast app because I don't have ios7 is there anything I can do?

    There are several very good third-party podcast apps you can download from the app store.
    Personally, I'm very happy with "DownCast".  I've given up on the apple podcast app, and DownCast seems to do everything I need.  My whole family uses it.

  • Ok apple I have one complaint and that is the fact that when I am on the Internet with my iPod I can't get onto the AppStore because it says cannot connect to iTunes store

    Ok apple I have one complaint and that is the fact that when I am on the Internet with my iPod I can't get onto the AppStore because it says cannot connect to iTunes store

    Can't connect to the iTunes Store
    Best Fixes for ‘Cannot Connect to iTunes Store’ Errors | iPad Insight

  • How can I get files to open automatically upon download?

    I would like files I download to open automatically and for the download window to be turned off. I know how to turn off the download window, but cannot get files to automatically download.

    Hi JJMack. Thanks for getting back to me.
    I think I've created confusion about what I want. All I want is to end up with a file that is flattened so that I can save it as a tiff without getting a warning that it contains layers. Please correct me if I’m wrong but I’ve always assumed I should always flatten a file before I save it as a tiff unless I specifically want to retain layers or transparency. I’m only talking here of files that open with a single layer: ie. Layer 1. I assume that if I don’t flatten such files the resultant files will be unnecessarily big?
    The only reason I keep saying I want a Background layer is that I know that a flattened file will only have a Background layer. I don’t have any desire for a Background layer per se. I certainly don’t want to add extra layers - quite the opposite.
    So perhaps the question I should have asked should have been:
    How can I get files to open 'ready-flattened' by default so I can save them directly to tiff without having to manually flatten them every time?
    Cheers

  • When I try to print a photo downloaded from Facebook in iPhoto, I can't get the size I specify to print correctly. Example: 5x7 prints smaller than 5x7. What do I do to solve this problem?

    When I try to print a photo downloaded from Facebook in iPhoto, I can't get the size I specify to print correctly. Example: 5x7 prints smaller than 5x7. What do I do to solve this problem?

    Those pixel dimemsions have aspect ratios that are not the same as a 5 x7 print:
    1360 x 1360 = 1.0
    790 x 640 = 1.23
    2048 x 1366 = 1.5
    An 7 x 5 image = 1.4.
    So you'll need to crop the images to 5 x 7 before printing.  The first two images are a little light in the pixels to produce a high resolution 5 x 7 print. 
    Happy Holidays

Maybe you are looking for

  • Help with mirroring drives

    Hi all.. I have an e450 box which has 2x18 GB hdd and 2x36 GB hdd & 2GB RAM. I have managed to install solaris 9 on it. I want to mirror the 2 18GB HDD & 2 36GB HDD. When I had to lay out the file system, I did the following: I had to choose c0t0d0 (

  • Where's the iPhone4s in THAILAND had essembled?

    As a result of ip4s in Thailand has released in 20,900 THB. I want to know where's the whole had been produced or imported from? Furthermore, does the price is included VAT or not? Thank You.

  • Pricing and Plans

    I'm currently on the Basic Plan ($14.99 per month). It looks like the Plus Plan paid annually is cheaper and allows for more forms, answers, etc. If I "upgrade" will the forms in my basic account swith over to the new plan? If so will they still have

  • Oracle BI Publisher Downloads

    Dear sir I download around 500mb of BI Publisher 10.1.3.3 for Windows x86 (701 MB) and now zip fill is not found on web site and recd message as below Sorry, this page was not found. (ErrorDocument 404) Can any one help me to complet my download with

  • How do I change from annual to monthly?

    Hey, I am currently enrolled with the Photography CC and wanted to upgrade to the "whole thing" after doing the trials of a few of the other applications. I went through the upgrade prompts, expecting that any time they would offer me a choice betwee