編寫一個Java Application程序
(1)從命令行后輸入任意個參數(shù),把參數(shù)用&符號連接成新的字符串,查找新的字符串中是否有gench,如果有,在控制臺輸出“上海建橋學院“
?(2)將新的字符串寫到文件D:\ myfile.txt中;
(3)要求處理該程序中所有可能出現(xiàn)的異常。
提示:
參考StringBuffer類里面的equals、append等方法
(1)從命令行后輸入任意個參數(shù),把參數(shù)用&符號連接成新的字符串,查找新的字符串中是否有gench,如果有,在控制臺輸出“上海建橋學院“
?(2)將新的字符串寫到文件D:\ myfile.txt中;
(3)要求處理該程序中所有可能出現(xiàn)的異常。
提示:
參考StringBuffer類里面的equals、append等方法
2015-12-03
舉報
2015-12-03
2015-12-05
package hello;
import java.io.*;
import java.util.Scanner;
/*import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;*/
public class Example03{
public static void main(String[] args) {
? ? Scanner input = new Scanner(System.in);
? ? String inputStr=input.next();
? ? input.close();
? ? String replaceStr=inputStr.replaceAll(",", "&");
? ? String[] str = replaceStr.split("&");
? ? for (String s : str) {
? ? ? ? if(s.equals("gench")){
? ? ? ? ? ? System.out.println("上海建橋學院");
? ? ? ? }
? ? }
? ? File file = new File("d:/myfile.txt");
? ? try {
? ? ? ? OutputStream outputStream = new FileOutputStream(file);
? ? ? ? OutputStreamWriter writer = new OutputStreamWriter(outputStream);
? ? ? ? writer.append(replaceStr);
? ? ? ? writer.close();
? ? ? ? outputStream.close();
? ? } catch (FileNotFoundException e) {
? ? ? ? e.printStackTrace();
? ? } catch (IOException e) {
? ? ? ? e.printStackTrace();
? ? }
}
}
2015-12-03
你這個輸入任意個參數(shù)之間是用什么分割的呢