LoginSignup
4
3

More than 5 years have passed since last update.

[Java:備忘録]プログラムに引数を与える

Last updated at Posted at 2014-09-17

概要:
 正確にはクラス:Mainに引数を与える。

目的:
 業務で個別PG組む際に割りと使うから。
 バッチ起動でデータ変換とかデータチェックとかする場合とか。

 ぐぐれば、もっと分かりやすく出てくるけど、自分が使う場合はこれで充分なので。
 つまり、備忘録。

ソース:

 /**
 * 引数確認&取込
 */
public class Hikisu {

    /**
     * @param args
     */
    public static void main(String[] args) {

        // 引数が一致しない場合は処理を終了させる.
        if (args.length != 2) {
            System.err.println("引数は2つ指定してください.");
            System.exit(1);
        }

        // 読み込むファイルの名前
        String foo = args[0];
        String hoge = args[1];  

        // 必要な処理を書く
    }
}

備考
 ちゃんと使うなら取得した引数値の内容もチェックしましょう。
 桁数とか、属性とか。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3