• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File.isFile() and File.isDirectory() both return false

 
Anirudh Aithal
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a function to list the contents of a directory. For the contents of the directory "/System", both isDirectoy and isFile functions return a false value. How is this possible? Please clarify.

The code snippet for reference:



I am getting logs in logcat like this:
V/->->FEX ( 350): in populateContents, fileList[0]: bin
V/->->FEX ( 350): in populateContents, fileList[0]: bin is neither a file nor a directory
V/->->FEX ( 350): in populateContents, fileList[1]: build.prop
V/->->FEX ( 350): in populateContents, fileList[1]: build.prop is neither a file nor a directory
V/->->FEX ( 350): in populateContents, fileList[2]: etc
V/->->FEX ( 350): in populateContents, fileList[2]: etc is a directory
V/->->FEX ( 350): in populateContents, fileList[2]: etc is a directory and is non-empty
V/->->FEX ( 350): in populateContents, fileList[3]: app
V/->->FEX ( 350): in populateContents, fileList[3]: app is neither a file nor a directory
V/->->FEX ( 350): in populateContents, fileList[4]: usr
V/->->FEX ( 350): in populateContents, fileList[4]: usr is neither a file nor a directory
V/->->FEX ( 350): in populateContents, fileList[5]: fonts
V/->->FEX ( 350): in populateContents, fileList[5]: fonts is neither a file nor a directory
V/->->FEX ( 350): in populateContents, fileList[6]: media
V/->->FEX ( 350): in populateContents, fileList[6]: media is neither a file nor a directory
V/->->FEX ( 350): in populateContents, fileList[7]: sounds
V/->->FEX ( 350): in populateContents, fileList[7]: sounds is neither a file nor a directory
V/->->FEX ( 350): in populateContents, fileList[8]: lib
V/->->FEX ( 350): in populateContents, fileList[8]: lib is neither a file nor a directory
V/->->FEX ( 350): in populateContents, fileList[9]: xbin
V/->->FEX ( 350): in populateContents, fileList[9]: xbin is neither a file nor a directory
V/->->FEX ( 350): in populateContents, fileList[10]: framework
V/->->FEX ( 350): in populateContents, fileList[10]: framework is neither a file nor a directory
V/->->FEX ( 350): in populateContents, fileList[11]: lost+found
V/->->FEX ( 350): in populateContents, fileList[11]: lost+found is neither a file nor a directory

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13077
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest there is no "/System" directory - are you sure about the S instead of s? Java does care about case.

Bill
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're just losing the path information. The File.list() call is returning the names of all the files in "dir", but then you are continuing to ask if each of the names exists, without telling Java what directory those names appear in. If you were to test nFile.exists(), you'd find that it returns false, as well.

How about this: replace File.list() with File.listFiles(), to get an array of File objects back; then just use those File objects directly. Either that, or create nFile like this:

File nFile = new File(file, fileList[ix]);

 
Anirudh Aithal
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I will try that.
Btw, "/System" was a typo. The directory "/system" does exist.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic