Java程序输入输出
- [前言](#前言)
- [实操](#实操)
- [编码环境](#编码环境)
- [Paragram Params](#paragram-params)
- [标准输入System.in](#标准输入systemin)
- [System类回顾](#system类回顾)
- [封装System.in](#封装systemin)
- [Scanner简述](#scanner简述)
- [Scanner类常用方法](#scanner类常用方法)
前言
最近突然收到好友提问如何在IDE里想Java程序传递参数,首先想到了Paragram Params,但是具体位置及基本配置竟一时无法想起。。。近一年来基本没有进行编码,悲哀。
实操
编码环境
IDE: IntelliJ IDEA
Paragram Params
Run(Alt+Shift+F10) –> Edit Config –>

VM Options,Environment variables, Redicct input 等配置
标准输入System.in
The “standard” input stream. This stream is already open and ready to supply input data. Typically this stream corresponds to keyboard input or another input source specified by the host environment or user.
System类回顾
Among the facilities provided by the System class are standard input, standard output, and error output streams; access to externally defined properties and environment variables; a means of loading files and libraries; and a utility method for quickly copying a portion of an array.
- init
1 | /** |
- standard in, standard out, standard err
以System.in为例介绍
1 | public final static InputStream in = null; //The "standard" input stream. This stream is already open and ready to supply input data. |
- externally defined properties and environment variables
- a utility method for quickly copying a portion of an array
1 | /** |
封装System.in
1 | Scanner scanner = new Scanner(System.in); |
Scanner简述
如果仅仅获取输入可以对System.in进行自定义的任何封装
A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace.
The resulting tokens may then be converted into values of different types using the various next methods.
The scanner can also use delimiters other than whitespace. This example reads several items in from a string:
1 | String input = "1 fish 2 fish red fish blue fish"; |
result: 1 2 red blue
The same output can be generated with this code, which uses a regular expression to parse all four tokens at once:
1 | String input = "1 fish 2 fish red fish blue fish"; |
The default whitespace delimiter used by a scanner is as recognized by java.lang.Character.java.lang.Character#isWhitespace(char) isWhitespace.
The reset method will reset the value of the scanner’s delimiter to the default whitespace delimiter regardless of whether it was previously changed.
Scanner类常用方法
1 | /** |