編寫一個(gè)Java Application程序
(1)從命令行后輸入任意個(gè)參數(shù),把參數(shù)用&符號(hào)連接成新的字符串,查找新的字符串中是否有g(shù)ench,如果有,在控制臺(tái)輸出“上海建橋?qū)W院”
?(2)將新的字符串寫到文件D:\ myfile.txt中;
(3)要求處理該程序中所有可能出現(xiàn)的異常。
提示:
參考StringBuffer類里面的equals、append等方法
(1)從命令行后輸入任意個(gè)參數(shù),把參數(shù)用&符號(hào)連接成新的字符串,查找新的字符串中是否有g(shù)ench,如果有,在控制臺(tái)輸出“上海建橋?qū)W院”
?(2)將新的字符串寫到文件D:\ myfile.txt中;
(3)要求處理該程序中所有可能出現(xiàn)的異常。
提示:
參考StringBuffer類里面的equals、append等方法
2015-12-03
舉報(bào)
2015-12-03
??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("請(qǐng)輸入一個(gè)字符串:");??????????????????????????????????????????????????? ??String?line;??????????????????????????????????????????????????????????????????????? ??try?{?????????????????????????????????????????????????????????????????????????????? ???line?=?br.readLine();?????????????????????????????????????????????????????????? ???System.out.println("你輸入的字符串是:"?+?line);???????????????????????????????????????? ???String?str?=?line?+?"&";??????????????????????????????????????????????????????? ???if?(line.contains("gench"))?{?????????????????????????????????????????????????? ????System.out.println("上海建橋?qū)W院");?????????????????????????????????????????????? ???}?????????????????????????????????????????????????????????????????????????????? ???bos.write(str.getBytes());????????????????????????????????????????????????????? ??}?catch?(IOException?e)?{?????????????????????????????????????????????????????????? ???e.printStackTrace();??????????????????????????????????????????????????????????? ??}?finally?{???????????????????????????????????????????????????????????????????????? ???try?{?????????????????????????????????????????????????????????????????????????? ????bos.close();??????????????????????????????????????????????????????????????? ???}?catch?(IOException?e)?{?????????????????????????????????????????????????????? ????e.printStackTrace();??????????????????????????????????????????????????????? ???}?????????????????????????????????????????????????????????????????????????????? ??}?????????????????????????????????????????????????????????????????????????????????? ??????????????????????????????????????????????????????????????????????????????????????????? ?}