| Author |
How to find a if a file exists by extention only?
|
Maja Gralewska
Ranch Hand
Joined: Sep 26, 2008
Posts: 92
|
|
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.
|
Potrzeba jest matka wynalazków
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
You can use a FilenameFilter in combination with File.list(FilenameFilter)
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19214
|
|
|
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.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Maja Gralewska
Ranch Hand
Joined: Sep 26, 2008
Posts: 92
|
|
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
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
Why are you using a CFileClientController (whatever that is) to check if the file exists and not just a File?
|
 |
Maja Gralewska
Ranch Hand
Joined: Sep 26, 2008
Posts: 92
|
|
|
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.
|
 |
 |
|
|
subject: How to find a if a file exists by extention only?
|
|
|