日期:2014-05-20  浏览次数:20606 次

新手提问:在Java中如何选择已经保存的Config(配置)文件并显示出来?谢谢!!(在线等)
具体问题如下:
        在目录中有原来保存的txt格式的配置文件,比如config1.txt,config2.txt,config3.txt……,现在我想在JFrame上通过一个JButton来实现点击Button后,显示所有的配置文件,然后在选择其中一个后,把配置文件里的Key和值显示在JFrame上的Lable和TextArea上。
谢谢!!!

------解决方案--------------------
File lists = new File(//config文件目录);
String listFile[] = lists.list();
添加一个Choice 下拉列表框,
for(int i = 0;i <listFile.length;i++)
Choice.add(listFile[i]);

Choice.addItemListener(this); //注册监听器


public void itemStateChanged(ItemEvent e)
{
try
{
BufferedReader bin= new BufferedReader(new inputStreamReader(new FIleInputStream(Choice.getSelectedItem())));

String temp = null;
while(temp = bin.readLine()) != null)
text.append(temp + '\n ');

bin.close();

}catch(Exception e){}


}
大概这样就可以,没编译运行,参考下