Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

only 'txt' files must be uploaded  RSS feed

 
Sandeep Swaminathan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using a file browser(JFileChooser) to display file select with which i'm loading the values into the database on a button click. How do I identify that the selected file is only a 'txt' file and the software must throw an error message if it isnt a text file! enlighten me ..
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Check the chosen file extension
2) Check out the JFileChooser API. You can provide filters, so that only certain type of files show up.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
google
ExtensionFileFilter

there are numerous examples you should be able to adapt to your needs
 
Sandeep Swaminathan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well well got a handful of examples .. thanks .. the truth is i didnt knew its called as 'file extension filter' :x
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!