• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to check for file extension in subfolder  RSS feed

 
John North
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

Kinda of new to Java. I have a program that allows the user to select what type (i.e. tif, jpg, sid) of file they have to load. I use a JCombo box for the selection type. I send this JCombo box string to my ElevationConvert class. What I want to do is check to see if that extension the user selected exists prior to converting it. If the file extension does not exist, I want to pop up a window (JOptionPane) stating is does not exit. I have tried suggestions found on this site, but does not seem to work for my application. The program works with (Process cN = Runtime), if I try not to check for the extension. But when I add the check for (If, else), it bombs. This executable runs in the main folder. The file extensions are in a subfolder called Ned. I hope you understand my question.


 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the File.list() or File.listFiles() methods. There are versions that take a FilenameFilter or FileFilter instance.
If you write a filter that matches on files with the given extension, you then just need to check the size of the returned array. If it's zero, no files match, greater than zero there are matching files.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!