为了账号安全,请及时绑定邮箱和手机立即绑定

编写一个Java Application程序

(1)从命令行后输入任意个参数,把参数用&符号连接成新的字符串,查找新的字符串中是否有gench,如果有,在控制台输出“上海建桥学院”

 (2)将新的字符串写到文件D:\ myfile.txt中;

(3)要求处理该程序中所有可能出现的异常。


提示:

参考StringBuffer类里面的equals、append等方法


正在回答

1 回答

  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();                                                       
   }                                                                              
  }                                                                                  
                                                                                           
 }


0 回复 有任何疑惑可以回复我~
#1

xiaoyu123669 提问者

非常感谢!
2015-12-05 回复 有任何疑惑可以回复我~
#2

xiaoyu123669 提问者

你写的字符没有保存到文件中
2015-12-05 回复 有任何疑惑可以回复我~
#3

HansonQ 回复 xiaoyu123669 提问者

有啊输完回车就有了啊
2015-12-05 回复 有任何疑惑可以回复我~
#4

xiaoyu123669 提问者 回复 HansonQ

谢谢,我加你好友吧
2015-12-05 回复 有任何疑惑可以回复我~
查看1条回复

举报

0/150
提交
取消
Java入门第三季
  • 参与学习       409792    人
  • 解答问题       4340    个

Java中你必须懂得常用技能,不容错过的精彩,快来加入吧

进入课程

编写一个Java Application程序

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信