老师,没有弄懂,就参考同学的把原来了改了改,有个问题,
“String[] itme =new String[]{".jpg",".zip",".doc"};”这句话中这些后缀啥作用,感觉没用,是下面跟路径有关联吗?
import java.awt.Color;import java.awt.BorderLayout;import java.io.File;import java.awt.Container;import java.awt.event.ActionEvent;import java.util.ArrayList;import java.util.List;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;public class FileUtils extends JFrame{ /** * 列出指定文件夹(目录)中的所有文件或目录的名额 * @param dri File类型指定的文件夹(目录) * @throws IllegalAccessException */ public static String listDirectory(File dir) throws IllegalAccessException{ if(!dir.exists()){ throw new IllegalAccessException("目录"+dir+"不存在"); } //判断dir下关联的文件和目录是否存在 if(!dir.isDirectory()){ //如果不存在抛出异常 throw new IllegalAccessException(dir + "不是目录"); } String[] fileName = dir.list(); String name =""; for(String a : fileName){ name=name+a+"\n";} return name; } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub // TODO Auto-generated method stub JFrame frame=new JFrame(); JPanel main_panel =new JPanel(new BorderLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //frame.setLayout(null); String[] itme =new String[]{ ".jpg",".zip",".doc"}; JComboBox box=new JComboBox(); for(int i=0;i