我有个文件a.txt内容为:(格式是  拼音+汉字)hz-汉族
hz-回族
zz-藏族
......现在用jcombobox来读取文本文件a.txt
怎么实现,请给出代码,谢谢

解决方案 »

  1.   

    BufferedReader in = null;
    List<String> list;
    try
    {
    in = new BufferedReader(new FileReader("C:\\a.txt"));
    String strLine = "";
    list = new ArrayList<String>();
    while ((strLine = in.readLine()) != null)
    {
    list.add(strLine);
    }
    } catch (FileNotFoundException ffe)
    {
    ffe.printStackTrace();
    } catch (IOException ioe)
    {
    ioe.printStackTrace();
    } finally
    {
    if (in != null)
    {
    try
    {
    in.close();
    } catch (IOException e1)
    {
    e1.printStackTrace();
    }
    }
    }if(list != null)
           combobox = new JComboBox(list.toArray());