使用JFileChooser可视化选择文件

这段代码是一段功能性的代码
功能是使用文件选择的可视化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;
		
	}
}

猜你喜欢

转载自blog.csdn.net/qq_41009846/article/details/82966475
今日推荐