(1)从命令行后输入任意个参数,把参数用&符号连接成新的字符串,查找新的字符串中是否有gench,如果有,在控制台输出“上海建桥学院”
(2)将新的字符串写到文件D:\ myfile.txt中;
(3)要求处理该程序中所有可能出现的异常。
提示:
参考StringBuffer类里面的equals、append等方法
BufferedOutputStream bos = null; try { bos = new BufferedOutputStream(new FileOutputStream( "D:\\myfile.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("请输入一个字符串:"); String line; try { line = br.readLine(); System.out.println("你输入的字符串是:" + line); String str = line + "&"; if (line.contains("gench")) { System.out.println("上海建桥学院"); } bos.write(str.getBytes()); } catch (IOException e) { e.printStackTrace(); } finally { try { bos.close(); } catch (IOException e) { e.printStackTrace(); } } }