使用JFileChooser視覺化選擇檔案
阿新 • • 發佈:2018-12-14
這段程式碼是一段功能性的程式碼 功能是使用檔案選擇的視覺化UI,選擇特定檔案 ,並且返回檔案物件File
package Judge; import java.io.File; import java.io.FileWriter; import javax.swing.JFileChooser; public class fileFiliter { public static File getFile() { JFileChooser fd = new JFileChooser(); // fd.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fd.showOpenDialog(null); File f = fd.getSelectedFile(); if (f != null) { } JFileChooser jf = new JFileChooser(); jf.setFileSelectionMode(JFileChooser.OPEN_DIALOG | JFileChooser.DIRECTORIES_ONLY); jf.showDialog(null, null); File fi = jf.getSelectedFile(); String f_ = fi.getAbsolutePath(); System.out.println("得到的檔案是:" + f); return f; } }