• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to find a if a file exists by extention only?  RSS feed

 
Maja Gralewska
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, im trying to find a file using only the extension irrelevant of what the name is but i cant seem to get it to work.
Here is my code, thanks.

 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use a FilenameFilter in combination with File.list(FilenameFilter)
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out java.io.File and its listFiles() methods. Using a FileFilter that checks if a name ends with .aut (case insensitive) will prevent other files being returned.
 
Maja Gralewska
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys i got that working but now i cant get it to read the file even if i pass it the static directory and name, any idea what im doing wrong? thanks


I have tried a few other ways but cant seem to get the data. It throws me a file not found exception, even though before it gets to the above code i do a check to see if the file exists to which it returns true. I have also tried a .txt file with the same results:



Data in the file(TEST.AUT) is as follows:

Maja
Gralewska
This is a test
Does it print out line by line

 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using a CFileClientController (whatever that is) to check if the file exists and not just a File?
 
Maja Gralewska
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, thanks for all the help its working perfectly now. Oh sorry bout that CFile works exactly like File only its a slightly customized method because we have to work through client controller, model, bean & persistence.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!