輸入法獲取位置信息 JFileChooser中如何獲取絕對(duì)路徑?
JFileChooser中如何獲取絕對(duì)路徑?JFileChooser chooser=新建JFileChooser()如果(選擇器.showOpenDialog(幀)=JFileChooser.APP
JFileChooser中如何獲取絕對(duì)路徑?
JFileChooser chooser=新建JFileChooser()
如果(選擇器.showOpenDialog(幀)=JFileChooser.APPROVE選項(xiàng))
{
文件fo=chooser.getSelectedFile文件()
字符串絕對(duì)路徑=獲取絕對(duì)路徑()
}
jFileChooser使用方法?
JFileChooserjFileChooser=newJFileChooser()inti=jFileChooser.showOpenDialog(null)如果(i==jFileChooser.APPROVE選項(xiàng)){//打開(kāi)文件stringpath=jFileChooser.getSelectedFile文件().getAbsolutePath()字符串名稱=jFileChooser.getSelectedFile文件().getName()系統(tǒng)輸出打印(“當(dāng)前文件路徑:”路徑“n當(dāng)前文件名:”名稱)}否則{系統(tǒng)輸出打?。ā拔催x擇文件”}
JFileFilter設(shè)置只顯示文件夾和指定后綴名的文件?
Jfilechooser filechooser=newjfilechooser()//創(chuàng)建一個(gè)文件選擇器文件選擇器.setCurrentDirectory(新文件()?!啊?/設(shè)置當(dāng)前目錄filechooser.setAcceptAllFileFilterUsed已使用(false)//顯示所有文件filechooser.addChoosableFileFilter(新建)javax.swing.filechooser文件選擇器. filefilter(){public Boolean accept(file f){return true}public string getdescription(){return“所有文件(*)。*) "})