I/O Error in File.listFiles()

Basically, I have the following piece of code:
public static void main(String[] args) {
    File f = new File("C:\\");
    search(f);
public static void search (File f) {
    if(f.isFile()) {
        if(contain(getEnd(f)))
            files.add(f);
    } else
        for(int i = 0; i < f.listFiles().length; i++) {
            search(f.listFiles());
}And a NullPointerException is thrown from this line: for(int i = 0; i < f.listFiles().length; i++) {
The source of the exception is obviously (correct me if I'm wrong) the listFiles() method, but "C:\\" does denote a directory, therefore this should have something to do with the I/O Error which may occur, according to the java API.
The API doesn't say much more about the I/O error, so my question is what could have caused it to occur, and what can be done to correct this issue?
Thanks in advance. =]
Edited by: Hirsch on Sep 11, 2008 2:23 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

The API clearly states that listFiles() can return null. I would prefer it returned an empty array, but no one asked me first.
Conclusion: look before you leap!
public static void search (File f) {
    if(f.isFile()) {
    } else {
        File[] files = f.listFiles();
        if (files != null) {
            for(File file : files) {
                search(file);
}another variation:
import java.io.*;
public class Example {
    public static void main(String[] args) {
       search(new File(".."));
    public static void search (File... files) {
        if (files != null) {
            for(File f : files) {
                if (f.isFile()) {
                } else if (f.isDirectory()) {
                    search(f.listFiles());
                } else {
}

Similar Messages

  • Problem with file.listFiles() of File class??

    Hi all friends,
    Iam facing with one peculiar problem,Iam using [file.listfiles()] method of File class in my program and this method of file class introduced in Java2.Now when Iam runing on Mac OS classic(8 to 9)[it is my client requirement they can't change Mac OS classic to Mac OS X] it is giving me error file.listfiles() not found in java.io package coz in Mac classic I have used MRJ2.2.6(for runtime) and MRJ SDK2.2 which is based on jdk1.1.8 and this method[listfiles()] added in java2.But now for me I can't change this method in program coz it is a big code and I have to change lot of things in my program.Can any one plz tell me can i find any (java.io) package of java2 seperately in the from of .jar or .zip so that i can keep it in my MRJCLASSES folder and from there I can import it in my program.Eagerly waiting for reply.
    Regards
    Bikash

    Just use File.list(). There are minor semantical differences but they are easy to work around.

  • Error in File

    Hi everyone,
    The following code create an execution time error and I can not find the solution for this.
    If you help me, I will be happy.
    import java.io.*;
    class Files {
         // properties
         static int first = 0;
         // constructor
         public Files(){
         // methods
              public static long listing(File files){
                   File[] fil = new File[files.listFiles().length];
                   if(first == fil.length ){
                        return fil[first].length() ;          
                   else{
                        fil = files.listFiles();
                        return listing(fil[first + 1]) + fil[first].length();
         public static void main(String args[])
              File myFile = new File("C:Program Files");
              System.out.println(listing(myFile));
         Errors:
    at Files.main(Files.java:31)

    The backslash character has to be escaped in string
    literals. Or, for
    filenames use forward slash.Thanks for this. But I can not save myself from execution errors.
    import java.io.*;
    class Files {
         // properties
         // constructor
         public Files(){
         // methods
         public static long listing(File files, int first){
              File[] fil = new File[files.listFiles().length];
              if(first == fil.length - 1){
                   return fil[first].length() ;          
              else{
                   fil = files.listFiles();
                   if(files.exists() == true)
                        return fil[first].length() + listing(fil[first + 1], first + 1);
                   else
                        return 1;
         public static void main(String args[])
              File myFile = new File("C:\\Program Files\\Java\\jdk1.5.0\\bin");
              System.out.println(listing(myFile, 0));
         The error says that listFiles() method returns nothing(null) instead of File array since fil array appears null when I execute the code.
    So please help me , what should I do ??

  • Web-Disk on OSX 10.9 Give me this error: "Finder got an error: Network file permission error."

    Previously I was using OSX 10.8 and Web Disk was working great.
    Since I upgraded to OSX 10.9 Web Disk Dont Attach to my compputer and give me this ERROR:
    FInder got an error: Network file permission error.
    When I got this ERROR first time I searched GOOGLE and found this link: http://cammodude.blogspot.no/
    And I did:
    To force all connections to be SMB1:
    Open A terminal window
    paste in the following line followed by the return key(should be all on one line): 
    echo "[default]" >> ~/Library/Preferences/nsmb.conf; echo "smb_neg=smb1_only" >> ~/Library/Preferences/nsmb.conf
    What the command does:
    Creates a file called nsmb.conf  in your  home directory at the path ~/Library/Preferences/nsmb.conf.
    Adds directives to force SMB connections to use the SMB1 protocol.  This is slower but stable.
    Then I could use Web Disk on OSX 10.9 after executing this command in Terminal.
    But now I restarted my Macbook and now Im NOT able to connect to Web Disk and get the same ERROR.
    FInder got an error: Network file permission error
    After trying 100 times it attaches 1 time but then show this ERROR:
    Can't get <<class cdis>> "my.server.com/2078" of application "Finder".
    If this happen then I can see the files in Finder and see the Contents and Size of files but if I open a PHP file in BBEdit then it shows BLANK.. But actually it is NOT blank.
    Now Im stuck How can I solve this? All help is highly appericated..
    Thank you so much...

    Hi,
    Make sure to chmod the app, something like this :
    chmod -Rf 777  secure_site_WebDisk.app
    (in my case the CPanel provided the app for my OSx version.)

  • [Solved] Error : The file or folder path /Probl?me 1 does not exist

    Hello,
    I encountered this error
    The file or folder <path>/Probl?me 2 does not exist
    while I was trying to open a directory already extracted from a zip file containing directories with special characters. In this case, it is a "è" that was misinterpreted as a "?".
    I searched the forums and on google, the solutions proposed do not work for me. Although, I have to deal with these files written in french, I would like to have my locale in english (US), with a system wide support for special characters.
    Attempt 1: Adding the option : iocharset=utf8 into the fstab, like this :
    fstab :
    # /etc/fstab: static file system information
    # <file system> <dir> <type> <options> <dump> <pass>
    none /dev/pts devpts defaults 0 0
    none /dev/shm tmpfs defaults 0 0
    /dev/cdrom /media/cd auto ro,user,noauto,unhide 0 0
    /dev/dvd /media/dvd auto ro,user,noauto,unhide 0 0
    /dev/fd0 /media/fl auto user,noauto 0 0
    /dev/disk/by-uuid/24ba75ac-e52d-40eb-a599-83b394b500b2 /boot ext2 defaults 0 2
    /dev/disk/by-uuid/c797f409-00bc-479a-b4d6-ab49943f644b / ext4 defaults 0 1
    /dev/disk/by-uuid/668427a8-5f51-42bd-a316-fc7984bf5f4f /var ext4 defaults 0 2
    /dev/sda7 swap swap defaults 0 0
    /dev/disk/by-uuid/417cd1b7-8f06-414b-84d5-e8714d9646ab /home ext4 defaults 0 2
    /dev/disk/by-uuid/ef9aa00e-0515-4d7b-aa23-8096e787250d /usr ext4 defaults 0 2
    /dev/disk/by-uuid/17d401b7-2fc7-4d9f-8e17-657d86926d2e /tmp ext4 defaults,iocharset=utf8 0 0 <<<<<<<<<<<<<<
    /dev/disk/by-uuid/71e543b6-e06c-4b0e-b1e3-3b491ff1fefe /var/cache/pacman/repos ext4 defaults 0 2
    #/dev/sda12 /mnt/archive ext4 defaults 0 2
    #.host:/ /mnt/hgfs vmhgfs defaults 0 0
    This solution does not work, because after adding iocharset=utf8, in front or after a "defaults", after a reboot, while mounting the filesystem, there is the following error message:
    Mounting Locale Filesystem :
    mount: wrong fs type, bad option, bad superblock on /dev/sdb1,
    missing codepage or helper program, or other error
    In some cases useful info is found in syslog - try
    dmesg | tail or so
    $ dmesg | tail
    phy0: Selected rate control algorithm 'iwl-agn-rs'
    EXT4-fs (sda5): re-mounted. Opts: (null)
    EXT4-fs (sda5): re-mounted. Opts: (null)
    EXT4-fs (sda6): mounted filesystem with ordered data mode. Opts: (null)
    EXT4-fs (sda8): mounted filesystem with ordered data mode. Opts: (null)
    EXT4-fs (sda9): mounted filesystem with ordered data mode. Opts: (null)
    EXT4-fs (sda10): Unrecognized mount option "iocharset=utf8" or missing value <<<<<<<<<<<<<<
    EXT4-fs (sda11): mounted filesystem with ordered data mode. Opts: (null)
    Adding 2104476k swap on /dev/sda7. Priority:-1 extents:1 across:2104476k
    tg3 0000:07:00.0: irq 44 for MSI/MSI-X
    Attempt 2: Changing all the locale features in KDE and in /etc/rc.conf as well.
    $ vim /etc/rc.conf
    LOCALE="fr_CA.utf8"
    HARDWARECLOCK=""
    TIMEZONE="America/Montreal"
    KEYMAP="us"
    CONSOLEFONT=
    CONSOLEMAP=
    USECOLOR="yes"
    It is complicated to remove these directories. I had to use the inum to get precisely these directories before removing them.
    $ ls -il
    total 8
    1577566 drwxr-xr-x 2 [username] [username] 4096 28 jan 07:09 Probl?me 1
    1577573 drwxr-xr-x 2 [username] [username] 4096 28 jan 07:09 Probl?me 2
    $ find . -inum 1577566 -exec rm -i {} \;
    rm: impossible de supprimer « ./Probl\212me 1 »: est un dossier
    Note that the hypothetical character 'è' is represented has a '\212', a 'È' if seen as a extended ASCII character.
    These directories cannot be deleted this way :
    $ rm -r Problème\ 1
    rm: cannot remove `Problème 1': No such file or directory
    or
    $ rm -r ProblÈme\ 1
    rm: cannot remove `ProblÈme 1': No such file or directory
    What should I do to be make the operating system recognize those special character, and interpret them correctly ?
    Last edited by ramboman (2011-01-29 21:45:50)

    I found a working solution, but better solution are also welcome
    I had to have fr_CA not only in utf8 but also in iso88591. I had to modify the /etc/rc.conf this way :
    LOCALE="fr_CA" <<<<<<<<<<<<<<
    HARDWARECLOCK=""
    TIMEZONE="America/Montreal"
    KEYMAP="us"
    CONSOLEFONT=
    CONSOLEMAP=
    USECOLOR="yes"
    To preserve the english US language system wide, I had to add the following line in the /etc/profile :
    # Allow french special character while in en_US
    export LANG=en_US
    The character misinterpreted by a "?" is now seen :
    as a "è" in dolphin
    as a "?" in the console
    It is now possible to access the folders.

  • My LR 4 suddenly no longer recognized my memory cards. I am using the same cards and cameras but consisitently get the error message:"files not imported because the files could not be read. they are jpg and nef files...I am stuck without my workhorse! Any

    My LR 4 suddenly no longer recognized my memory cards. I am using the same cards and cameras but consisitently get the error message:"files not imported because the files could not be read. they are jpg and nef files...I am stuck without my workhorse! Any advice is helpful. This has never happened in 6 years

    answered in your other thread LR 4 suddenly no longer recognizes files.

  • I have the following error The file "iTunes library.itl" cannot be read because it was created by a newer version of iTunes

    Can anyone help me with this problem.  I tried updating the latest itunes and it caused an error MSVCR80.dll missing.  I then tried fixing it after reading other people had the same problem and a solution was given about uninstaling itunes and the order in which to do that.  I did that but now get the error "the  files "itunes library.itl" cannot be read because it was created with a newer version of itunes.  I see a solution has been given about this but I cannot find what is suggested to enable me to follow instructions.  Can anyone please go through step by step (letting  me know where I can find what is needed) to enable me to be able tio log into itues again.  Thanks

    Hi pussygalore,
    If you are having issues with iTunes after an attempted update, you may find the following article helpful:
    iTunes 11.1.4 for Windows: Unable to install or open
    http://support.apple.com/kb/TS5376
    You may want to make sure that in the last step (reinstalling iTunes) that you are installing the latest/newest available version, and not attempting a reinstall from an older file.
    Regards,
    - Brenden

  • File Error:Unknown File.

    I am getting a "File Error:Unknown file" when i try and save my project. So i am not able to save any changes i make to my project. any thoughts?

    Try FILE>Save Project As.
    does that work?
    Shane

  • "File error: unknown file" upon movie import

    Got a DVD. Extracted the footage with Mac the ripper. Created an mp4 file with Handbrake. It plays fine in Quicktime at 720 by 480 and 23.98 FPS. I've tried importing it into FCP and I get the error, "File error: unknown file". FCP sequence presents are 24 FPS...I've also tried switching it to 23.98 FPS. I've re-encoded the movie in Quicktime to a .mov file with "DV/DVCPRO - NTSC" compression and it still will not import. Any suggestions?

    Tried making an AVI in Handbrake. Handbrake just froze everytime and it would never finish.
    I should also note that FFMpeg did not like the footage either and would not convert it to a file of any kind.
    So I put the DVD into a consumer DVD player and used my Panasonic DVX100B camera to record the footage in VCR mode. The tape turned out fine.
    BUT...
    I am trying to capture the footage from another low end Canon camera. Usually there is no problem. However, with this particular footage from this cursed DVD, I get a "general error" when I try to capture the footage in FCP.
    No matter what file format or media is used, this footage will not import into FCP. It must be watermarked to not like FCP.
    Any further suggestions???

  • File Error: Unknown File when trying to render a Motion Lower third

    I'm getting this: "File Error: Unknown File" when trying to render a Lower third made in the Motion tab. I'm using FCP 6.0.6 and haven't had any issues with this before. It seems to work fine if there is just text, but as soon as I apply any effect, like a drop shadow, I get that error message.
    Thanks,
    Joe

    What's the exact format of the video you're working with and the exact specification the sequence you're editing in?

  • File Error - Unknown file when trying to import from HDD camera

    I recently purchased a Panasonic SDR-H80 and am trying to get my widescreen footage into FCP. I converted the .MOD files to .m4v files in Handbrake, and they play and look fine in the Finder. However, when I try to move them into FCP, I get a dialog that says "File Error - Unknown file." I'm not sure what I'm doing wrong here. Can anybody help?

    I converted the .MOD files to .m4v files in Handbrake .... I'm not sure what I'm doing wrong here
    What you're doing wrong is using Handbrake and trying to use .m4v files in FCP. Neither is the correct process in preparing for editing.
    Try using MPEG Streamclip and a format that actually works natively in FCP. .m4v is a final delivery format- not for editing. A search on this forum would have revealed that to you in a matter of seconds: http://discussions.apple.com/search.jspa?objID=c206&search=Go&q=handbrake
    -DH

  • File Error: Unknown File, Cannot Save

    I hope this is only a matter of healthy file management, but I'm quite confused and hope someone can clear this up into something of a simple science. On the otherhand, could this be a LIMITATION of FCP?
    -Have been editing a sequence from a larger film on a second computer. That sequence has been worked on over several days and saved (of course). However, upon saving last night, was an error message: "File error: Unknown File" and the project could not be saved.
    -This is quite possibly due to the fact that both the media and project files have been copied over the network to the first computer where the master project is being assembled.
    -HOWEVER, no media files claimed to be offline, everything was editable AND the FILE WOULD NOT SAVE through multiple attempts
    -ALSO, the other open project WOULD NOT SAVE either (its files where never moved or otherwise tampered with. It was a small and entirely local operation).
    -SAVING was finally accomplished ONLY by saving the project file to the LOCAL HD rather than the EXTERNAL DRIVE where the MEDIA and PROJECT FILES originated and had been previously saved to.
    -All other attempts to save to the EXTERNAL were met with the message "FILE ERROR: UNKNOWN FILE" This compromised saving process resulted in the loss of all work, edits, etc. on the LESSER and EXCLUSIVELY local project.
    -AFTER saving to the LOCAL HD, the project COULD BE once again saved to the EXTERNAL HD. This flow seemed very strange to me.
    -Has anyone else encountered this problem, and what can I correct in my processes to avoid this.
    --*Also, the First computer encountered the same problems at the same time, after both EDITING & SAVING had taken place since the last FILE COPYING. Again, work was lost.
    Thanks for any help you can offer.
    G5 Dual 2 GHz PowerPC   Mac OS X (10.4.5)   1.5 GB ram

    Do people search this forum at all?!?
    Check your project for CMYK files.
    Search this forum for General Error.
    This was discussed about 90 minutes ago.

  • File Error: Unknown File when saving

    I tried to save my project to the drive I've been working in and saving all day. And all of a sudden Im getting a new error: File Error: Unknown File. What's that all about? It saved fine to another drive.

    km@ms, Welcome to the forums.
    You have posted in a topic started by someone else in the pro video discussions.
    While someone here may well have an answer for you, it would be far better to ask your question as it's own topic. As a rule, you will receive an answer much sooner.
    Here is a link to the general discussion category for Mac OS X 10.4:
    http://discussions.apple.com/category.jspa?categoryID=177
    Here is the link to the "Pages" forum. http://discussions.apple.com/forum.jspa?forumID=1191
    While your issue is unrelated to that software product, you stand a better chance of finding someone familiar with Quark and .eps files there.

  • File Error: Unknown File - when doing save as

    yet another variation on the file problems i am having.
    opened an aotosave file and tried to 'Save project as",
    wont do it, reports "File error: unknown file"
    the same error i get often when trying to "save as" the original,
    and the same error i get if i make a copy of the FCP file in the finer, open it and try to save it, it wont do it.....
    so with the main sequence in my project getting lost ("not found"),
    i now find that its almost impossible to make a backup that works....
    anyone know about this SERIOUS FAULT.
    i can think of no reason why it cant handle the most basic act of keeping assets attached to the program.
    new computer, new drives, new everything..
    i am now working really scared, when it loses the main sequence again (1 hour), the latest backup that might work could be anything from 1 - 5 days old, who knows, and there goes days of work...
    ======================================
    FCP6
    HDV captures.
    Main sequence is prores render.
    Files and media on one 750G drive in the Mac Pro box.
    deleted all render files yesterday, now only about 15 there.
    changed MP3 tracks to aif.
    have done FCP resue often
    have done permissions
    have upgraded to 10.4.10

    i now find that its almost impossible to make a backup that works....
    anyone know about this SERIOUS FAULT.
    i can think of no reason why it cant handle the most basic act of keeping assets attached to the program.
    new computer, new drives, new everything..
    Except that this issue is almost always totally unrelated to FCP at all.
    Paulo has dome great anecdotal advice but this is usually a fiel permissions problem. No idea how it gets changed but you can run Disk Utility and repair permissions. Do it twice. then Get Info on your drive and see what the privileges are. Do the same for your FCP projects folders. Get info on your FCP project file itself.
    You need to get this figured out before you invest any more time in editing.
    bogiesan

  • File Error:  Unknown file.  - Importing problem

    I recently had some problems getting my FCP 5.0.4 to launch. To make a long story short someone in this forum said that my version of FCP was out of date with my current Macbook Pro running 10.5.5. I found this a little odd because I've had this computer for over six months and have been running FCP the whole time without a single problem. Since funds are tight and I don't have the money upgrade I did some troubleshooting to see if I could make it work again.
    I did remember that I had recently moved some of my older quicktime codecs into my library/quicktime folder and when I removed them I was able to launch and run FCP.
    Now when I try to import files I'm getting a "File Error: Unknown file" error message. I am able to view all the quicktimes and am only able to import a few quicktimes. I have quicktimes from the last six years that I'm trying to import so there's a good variety of different codes that were used. But I am able to watch all of the quicktimes via Quicktime.
    Any suggestions why I might be getting this problem? Any way to fix this without upgrading? Thanks

    *I recently had some problems getting my FCP 5.0.4 to launch.*
    The reason is because that version of for PPC Macs, and you have an Intel Mac.
    *Someone in this forum said that my version of FCP was out of date with my current Macbook Pro running 10.5.5*
    It doesn't matter which OS version is running. You need an Intel/UB version of FCP to run on a Intel Mac.
    *Any way to fix this without upgrading?*
    It's not a problem. It's an incompatibility. Because you have run it for some time without an incident is incidental to its incompatibility.

Maybe you are looking for

  • How to identify manual journal entries

    Hello, In the GL tables, GL headers and GL Lines, how can we identify if a journal entry is an automated entry or a manual entry. That is, entries can be made into the General ledger through Interface programs or other import methods. We describe the

  • Promblem in opening file through scripting?

    I want to open a file in photoshop through javascript but i dont know how to specify path of the file in the script. I'm a mac user and new to scripting.........Pls help!!!!

  • Xsl stylesheet path not founnd

    Receiving error: "javax.xml.transform ...   exception Invalid uri 'http://localhost/....  escaped absolute path not valid." Stylesheets cannot be found by irpt unless changed to actual path like "C:\Inetpub\wwwroot\.... Thanks, Ed  (for Shari)

  • How to "kill" RMIRegistry

    Hello, I have some class with main method, in which I create RMIRegistry by LocateRegistry.createRegistry(Registry.REGISTRY_PORT);When main method is finished, thread is ending, but registry is still running in other thread. How to make registry to s

  • Analyze table 10g steps

    Hi, DB: 10.2.0.4 RAC ASM OS: AIX 5.3L 64-bit I want to do analyze tables for all users.Please give me the steps for table and schema level. Thanks & Regards, Sunand