Output says "The number of bytes in the file are 0" but the file has bytes

Dear Java People,
Why would an output say a file has 0 bytes when upon doing a search for the file in Windows Explorer it say the file has 1 -4 kbytes ?
for example part of my output was :
"the number of bytes in TryFile3.java are 0"
caused by the following lines of code:
System.out.println("\n" + contents[i] + " is a " +
(contents.isDirectory() ? "directory" : "file\n") +
" last modified on " + new Date(contents[i].lastModified())
+ "\nthe number of bytes in TryFile.java are " + myFile.length());
thank you in advance
below are the two program classes
Norman
import java.io.File;
import java.io.FilenameFilter;
import java.util.Date;
public class TryFile3
   public static void main(String[] args)
       //create an object that is a directory
         File myDir =
        new File("C:\\Documents and Settings\\Gateway User\\jbproject\\stan_ch9p369");
          File myFile = new File(myDir, "TryFile3.java");
        System.out.println("\n" + myDir + (myDir.isDirectory() ? " is" : " is not")
        + " a directory.");
         System.out.println( myDir.getAbsolutePath() +
         (myDir.isDirectory() ? " is" : " is not") + " a directory.");
          System.out.println("The parent of " + myDir.getName() + " is " +
          myDir.getParent());
           //Define a filter for java source files Beginning with the letter 'F'
           FilenameFilter select = new FileListFilter("F", "java");
           //get the contents of the directory
           File[] contents = myDir.listFiles(select);
            //list the contents of the directory
         if(contents != null)
             System.out.println("\nThe " + contents.length  +
             " matching item(s) in the directory " + myDir.getName() + " are:\n " );
             for(int i = 0; i < contents.length; i++)
               System.out.println("\n" +  contents[i] + " is a " +
               (contents.isDirectory() ? "directory" : "file\n") +
" last modified on " + new Date(contents[i].lastModified())
+ "\nthe number of bytes in TryFile3.java are " + myFile.length());
else {
System.out.println(myDir.getName() + " is not a directory");
System.exit(0);
import java.io.File;
import java.io.FilenameFilter;
import java.util.Date;
public class FileListFilter implements FilenameFilter
private String name; // file name filter
private String extension; // File extension filter
public FileListFilter(String name, String extension)
this.name = name;
this.extension = extension;
// static boolean firstTime = true;
public boolean accept(File diretory, String filename)
//the following line of code can be inserted in order to find out who called the method
// if(firstTime)
// new Throwable("starting the accept() method").printStackTrace();
boolean fileOK = true;
//if there is a name filter specified, check the file name
if(name != null)
fileOK &= filename.startsWith(name);
//if there is an extension filter, check the file extension
if(extension != null)
fileOK &= filename.endsWith('.' + extension);
return fileOK;

System.out.println("\n" + contents + " is a " +
(contents.isDirectory() ? "directory" : "file\n") +
" last modified on " + new Date(contents.lastModified())
+ "\nthe number of bytes in TryFile.java are " + myFile.length());I haven't read any of your italicized code, but perhaps there is a good reason why you have "myFile.length()" and not "contents.length()" in this line of code?

Similar Messages

  • How to prevent the Firefox cache from clearing -- all settings are right, but the cache is gone after each restart.

    I want to prevent cache from being deleted after each restart. "Clear history when Firefox closes" is unchecked. User.js files are deleted. Checking "Override automatic cache management" made Cache folder appear in addition to Cache2. After exiting Cache is still there, but upon Firefox re-launching, Cache turns into Cache.Trash and promptly disappears. What to do?

    Hello,
    I'm sorry to hear that. Can you please try these solution to address your concern.
    Certain Firefox problems can be solved by performing a ''Clean reinstall''. This means you remove Firefox program files and then reinstall Firefox. Please follow these steps:
    '''Note:''' You might want to print these steps or view them in another browser.
    #Download the latest Desktop version of Firefox from [https://www.mozilla.org mozilla.org] (or choose the download for your operating system and language from [https://www.mozilla.org/firefox/all/ this page]) and save the setup file to your computer.
    #After the download finishes, close all Firefox windows (or open the Firefox menu [[Image:New Fx Menu]] and click the close button [[Image:Close 29]]).
    #Delete the Firefox installation folder, which is located in one of these locations, by default:
    #*'''Windows:'''
    #**C:\Program Files\Mozilla Firefox
    #**C:\Program Files (x86)\Mozilla Firefox
    #*'''Mac:''' Delete Firefox from the Applications folder.
    #*'''Linux:''' If you installed Firefox with the distro-based package manager, you should use the same way to uninstall it - see [[Installing Firefox on Linux]]. If you downloaded and installed the binary package from the [http://www.mozilla.org/firefox#desktop Firefox download page], simply remove the folder ''firefox'' in your home directory.
    #Now, go ahead and reinstall Firefox:
    ##Double-click the downloaded installation file and go through the steps of the installation wizard.
    ##Once the wizard is finished, choose to directly open Firefox after clicking the Finish button.
    More information about reinstalling Firefox can be found [[Troubleshoot and diagnose Firefox problems#w_5-reinstall-firefox|here]].
    <b>WARNING:</b> Do not use a third party uninstaller as part of this process. Doing so could permanently delete your [[Profiles|Firefox profile]] data, including but not limited to, extensions, cache, cookies, bookmarks, personal settings and saved passwords. <u>These cannot be easily recovered unless they have been backed up to an external device!</u> See [[Back up and restore information in Firefox profiles]]. <!-- Starting in Firefox 31, the Firefox uninstaller no longer lets you remove user profile data.Ref: Bug 432017 and https://support.mozilla.org/kb/uninstall-firefox-from-your-computer/discuss/5279 [Fx31] Windows uninstaller will no longer offer the option to remove personal data -->
    Please report back to say if this helped you!
    Thank you.

  • Photos have a ? in the top left hand corner.  When I click to reconnect files are found but the reconnect button is not active

    Mostr f my photos have a question mark in the top left hand corner.  When I go to <file> and click on reconnect the missing files are searched for and found but the reconnect button is not active. What can I do.  I m unable to edit these photos.

    jeglee
    What version of Premiere Elements are you using and on what computer operating system is it running?
    It sounds like you are in the Elements Organizer that came with your version of Premiere Elements.
    That ? in the top left corner of the thumbnail indicates a file that is no longer in the hard drive save location as it was
    when a copy of the file was included in the Elements Organizer.
    1. Do you know that the file(s) still exist? Could you have moved, deleted, or renamed file/folder involved? Can you go
    to the hard drive save location for the file and actually find it there?
    If you are working with Photoshop Elements instead of Premiere Elements, you have posted in the wrong forum. In that case, please post your thread in the Adobe Photoshop Elements Forum or wait for a moderator to see your thread here and move it from here to there.
    Photoshop Elements
    If not, we will continue our exchanges of information here in order to resolve your issue.
    Thank you.
    ATR

  • Is it necessary to fill in the number of my credit card to get access to the apps? What if I don't have one?

    Is it necessary to fill in the number of my credit card to get access to the apps? What if I don't have one?

    How to Get Apps From the App Store Without a Credit Card
    http://ipadhelp.com/ipad-help/how-to-get-free-apps-from-the-app-store-without-a- credit-card/
    Creating an iTunes Store, App Store, iBookstore, and Mac App Store account without a credit card
    http://support.apple.com/kb/ht2534
     Cheers, Tom

  • HT1766 My mini Ipad is only 2 months old and it has frozen. The screen says that the ipad needs to be backed up on icloud but the touch screen has frozen and I can even shut it down. Suggestions

    Does anyone know how to unfreeze a screen.
    My mini Ipad is only 2 months old and it has frozen. The screen says that the ipad needs to be backed up on icloud but the touch screen has frozen and I can even shut it down. Suggestions

    Try to reboot it. Hold down the sleep and home keys until you see the silver apple, about 20 seconds or so. It should reboot and work for you.

  • HT3702 Is there any limit to the number of itunes account that can be linked to the one credit card?

    Hi.  Does anyone know if there is a limit to the number of itunes accounts that can be linked to the one credit card? 
    Thanks,
    Nelliemay

    Craig,
    It was image.cpp line 2770.  I am told (by another person in the company that has seen this) that it has been seen on several machines, always PXI controllers, but not on all PXI controllers.  I am told that it is not always image.cpp that reports the error, but for me it was always the same line of code identified by the error message.  I did not have a chance to do any experimenting to find a particular threshold number of mnu files.  I may be able to find error logs.  I currently sent the controller to our IT department, doing a windows XP repair, just in case there was something corrupted in the system itself.
    The error was reproducible.  This installation at one time must have included real-time / FPGA, because on the opening screen I ge the drop-down ring for selecting a target.  If I click on this drop down ring, I get the crash on line 2770, every time.  If, instead I open an empty new VI, I am able to switch to the block diagram by selecting the window directly with the mouse, but if I try to pull down on the "window" menu to do "show block diagram", I get the crash on line 2770, every time.  Because the user-defined mnu files are now deleted, I would have to create them again, or find a way to reinstall them, to reproduce the error at this point.
    Vinny

  • Is there a way to Limit the number of guest accounts a Sponsor can create from the sponsor portal?

    Hello,
    I am trying to find a way to limit the number of guest accounts a Sponsor can create from the portal. I am running ISE 1.2 and I am finding it difficult to limit the number of guests a sponsor can create.

    Interesting feature that unfortunately is currently not possible. I also don't think this is a feature that will be offered in the highly anticipated v1.3. I would recommend that you reach to your Cisco team and request this feature. 
    Thank you for rating helpful posts!

  • I want install an old version of itune since the new version does not sync with my iPhone  but the old version I installed did not play rather it says that it can't read a file itune library .itl written by Newer version what do Ido

    I install an old version of itune since the new version does not sync with my iPhone  but the old version I installed did not play rather it says that it can't read a file 'itune library .itl' written by Newer version of itune how do I installed this old version to work

    You need to restore the pre-upgrade backup of the library file in the manner shown in  Empty/corrupt library after upgrade/crash.
    tt2

  • HT5035 I had $8 from a gift card in my acct then redeemed the number from a second gift car of $30. The $8 disappeared and now there's only $30 rather than $38? Any ideas?

    I had $8 from a gift card in my acct then redeemed the number from a second gift car of $30. The $8 disappeared and now there's only $30 rather than $38? Any ideas?

    Good advice

  • I am trying to update my billing detail on my IPAD2. However it keep on saying that the country need at least 3 characters long. But the country field is a dropdown list with Malaysia's states all with 2 characters long only! I can't make any purchase now

    I am trying to update my billing detail on my IPAD2. However it keep on saying that the country need at least 3 characters long. But the country field is a dropdown list with Malaysia's states all with 2 characters long only! I can't make any purchase now because I can't verify the billing detail because it just doesn't work! Very frustrating now.

    Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • The number 63 is highlighted in an orange box on the bottom left of the screen.

    I think that this number refers to the number of times that I have opened something on the internet. I can eliminate it by clicking on close 63 times but I think that there is an easier way to close sites I have opened. I believe that having this many sites open causes my computer to operate more slowly.

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]
    * [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    * Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")

  • I broke the screen on my ipod touch 4th gen and im trying to do a backup on the data but it says i need to enter a passcode on my ipod but the screen dosent work so what can i do

    hey i broke the screen on my ipod touch 4th Gen and im trying to do a backup on the data but it says I need to enter a passcode on my ipod but the screen dosent work so what can I do.

    You can't backup the iPod t iTunes then. You will have to use an existing iTunes backup.
    If iCloud backup is turned on and the iPod is still working (not disabled), the iPod will automatically backup daily if an internet connection is available and the iPod is connected to a charging source.

  • TS3899 I have an iPhone 5 and it shows on the Mail Icon that I have over 3,000 emails to read but the number continues to increase even when I have read the email.  I thought  once you have read an email it drops off the count of "new emails"

    I have an iPhone 5 and it shows on the Mail Icon that I have over 3,000 emails to read but the number continues to increase even when I have read the email.  I thought  once you have read an email it drops off the count of "new emails"

    The received emails should show in two locations:
    1. In the All Inboxes tab of Mail.
    2. The Inbox for each mail account,
    If your emails are not showing in these locations try quitting the mail app and then reset your iPhone.
    Go to the Home screen and double click the Home button. That will reveal the row of recently used apps at the bottom of the screen. Tap and hold on the app in question until it wiggles and displays a minus sign. Tap the minus sign to actually quit the app. Then tap anywhere on the screen above that bottom row to return the screen to normal.
    To reset your device. Press and hold the Home and Sleep buttons simultaneously ignoring the red slider should one appear until the Apple logo appears. Let go of the buttons and let the device restart. See if that fixes your problem.

  • Just got the 5c and my music list are here but the music isn't. It says I have to download them! Buy doing this does it mean I have to pay for them again??

    Just got the 5c and my music list are here but the music isn't. It says I have to download them! Buy doing this does it mean I have to pay for them again??

    Check the link below for requirements and instructions for upgrading to Snow Leopard (10.6)
    http://store.apple.com/us/product/MC573/mac-os-x-106-snow-leopard

  • I am trying to instal the latest version of iTunes onto my MacBook Pro, but my computer has been "configuring" the installation since 5pm yesterday and now it is 10:30am. It has never done this before. Can anybody help me out?

    I am trying to instal the latest version of iTunes onto my MacBook Pro, but my computer has been "configuring" the installation since 5pm yesterday and now it is 10:30am. It has never done this before. Can anybody help me out?

    Many thanks b Noir
    This is a copy of ONEof the keys  in the registry I changed  as told by Apple support today. I also have changed others as instructed by GEAR  software support to manually delete GEAR drivers (that I had installed but couldn't delete some of the others  they mentioned from Windows system 32. Then some bright spark at work told me I need the Gear drivers so  I downloaded the software and installed again.
    Sorry, just this minute went to insert image  and it is giving me a message saying this sort of content  is not allowed?.
    The most recent key I altered is in: HKey _local _machine. System\class - 4D36E965-E325-11CEBFC1-08002BE10318. Upper Filter data: Upper filter NTIDrvr  SiRem GEARAspiWDN.
    The GEARsoftware info about manually deleting  GEAR drive is from:
    http://www.gearsoftware.com/wiki/index.php?title=DRIVERS:_Windows_-_Updating%2C_ removing%2C_64_bit_versions%2C_etc
    I hope you can help

Maybe you are looking for