(1) 建立一个文本文件file1.txt,里面包含多行内容,其中有一组手机号码和座机号码,分散在文件里。
(2) 建立GUI界面,读文件file1.txt显示。
(3) 使用正则表达式的字符串匹配查找功能,从文本文件里找出所有电话号码并存放在Collection列表中,排序后,显示在GUI界面上。

字符串与输入输出流读写程序设计
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- devmiao 2018-05-20 11:46关注
读文件显示到界面的关键代码
class app1 implements ActionListener { public String readToString(String fileName) { String encoding = "UTF-8"; File file = new File(fileName); Long filelength = file.length(); byte[] filecontent = new byte[filelength.intValue()]; try { FileInputStream in = new FileInputStream(file); in.read(filecontent); in.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { return new String(filecontent, encoding); } catch (UnsupportedEncodingException e) { System.err.println("The OS does not support " + encoding); e.printStackTrace(); return null; } } public void actionPerformed(ActionEvent e) { if(e.getSource() == button1) { String s = readToString("file1.txt"); Test.text1.setText(String.valueOf(s)); } } }
若要完整程序,请先采纳。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报