Advertisement
RupeshAcharya60

FileChooser Java

Mar 25th, 2023
745
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.48 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.io.*;
  3.  
  4. public class FileChooserExample {
  5.     public static void main(String[] args) {
  6.         JFrame frame = new JFrame("File Chooser Example");
  7.  
  8.         JFileChooser chooser = new JFileChooser();
  9.         int result = chooser.showOpenDialog(frame);
  10.  
  11.         if (result == JFileChooser.APPROVE_OPTION) {
  12.             File file = chooser.getSelectedFile();
  13.             System.out.println("Selected file: " + file.getAbsolutePath());
  14.         }
  15.     }
  16. }
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement