[J2SE] 檔案類型判斷 Netbeans
不確定是不是netbeans的問題
我要判斷mime-type
在netbeans裡面執行時 可以正確判斷
可是我用他輸出的JAR檔時 卻不能判斷
每個都輸出application/octet-stream
我只是要去判斷我選的檔案是否為圖片檔而已
以下是判斷檔案的程式碼
public void open()
{
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
if (chooser.showOpenDialog(getContentPane()) ==
JFileChooser.APPROVE_OPTION)
{
Filename= (chooser.getSelectedFile().getAbsolutePath());
System.out.println(Filename);//抓取的檔案
photoname=chooser.getSelectedFile().getName();
extendname=MimetypesFileTypeMap.getDefaultFileTypeMap()
.getContentType(chooser.getSelectedFile());
System.out.println(extendname);
this.jLabel2.setText(photoname);
}
if(!"image/jpeg".equals(extendname)&&!"image/png".equals(extendname)
&&!"image/bmp".equals(extendname))
{
this.jLabel1.setText("檔案格式不符 請重新選擇"+extendname);
this.jMenuItem1.setEnabled(false);
}
else
{
this.jLabel1.setText("選擇檔案為 : "+this.photoname);
this.jMenuItem1.setEnabled(true);
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.243.214.236
※ 編輯: liar2 來自: 111.243.214.236 (05/16 13:31)
推
05/16 13:46, , 1F
05/16 13:46, 1F