使用文本文件填充JCombobox

可能重复:
如何从文本文件中填充JComboBox?

我是Java新手,只有2个月的经验。 任何人都可以帮我填充一个包含5行文本文件的JComboBox吗? 我查看了Google上的代码,但我一直在收到错误。

 private void populate() { String[] lines; lines = readFile(); jComboBox1.removeAllItems(); for (String str : lines) { jComboBox1.addItem(str); } } 

这是readFile()。 来自这个网站

 private String[] readFile() { ArrayList arr = new ArrayList<>(); try { FileInputStream fstream = new FileInputStream("textfile.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine; while ((strLine = br.readLine()) != null) { arr.add(strLine); } in.close(); } catch (Exception e) { } return arr.toArray(new String[arr.size()]); }