Choose a File : Files « File Input Output « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » File Input Output » FilesScreenshots 
Choose a File
Choose a File


import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JFrame;

public class FileFilterDemo {
  public FileFilterDemo() {
  }

  public static void main(String[] args) {
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("."));

    chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
      public boolean accept(File f) {
        return f.getName().toLowerCase().endsWith(".gif")
            || f.isDirectory();
      }

      public String getDescription() {
        return "GIF Images";
      }
    });

    int r = chooser.showOpenDialog(new JFrame());
    if (r == JFileChooser.APPROVE_OPTION) {
      String name = chooser.getSelectedFile().getName();
      System.out.println(name);
    }
  }
}


           
       
Related examples in the same category
1. Find out the directoryFind out the directory
2. Listing the Directory ContentsListing the Directory Contents
3. Random FileRandom File
4. Data fileData file
5. Output to a text File
6. Read data from text file
7. Copy File
8. Querying a File for Information
9. Working with RandomAccessFileWorking with RandomAccessFile
10. Get a list of files, and check if any files are missing
11. Delete a file from within Java
12. Work with temporary files in Java
13. Compare File Dates
14. Strings -- extract printable strings from binary file
15. File Name Bean
w_w___w_.__j__a__v_a_2_s___._co__m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.