system.setin
系統類setIn()方法 (System class setIn() method)
setIn() method is available in java.lang package.
setIn()方法在java.lang包中可用。
setIn() method is used to assign again the standard input stream.
setIn()方法用于再次分配標準輸入流。
setIn() method is redirected because it does not read the input from the editor.
setIn()方法被重定向,因為它不從編輯器讀取輸入。
setIn() method read the input from the standard input stream.
setIn()方法從標準輸入流中讀取輸入。
setIn() method is a static method, it is accessible with the class name too.
setIn()方法是靜態方法,也可以使用類名進行訪問。
setIn() method may throw an exception while reading the input from the standard input stream:
從標準輸入流中讀取輸入時, setIn()方法可能會引發異常:
SecurityException: In this exception checkPermission() method does not allow reassigning of the latest standard input stream when security manager exists.
SecurityException:在此異常中,當存在安全管理器時,checkPermission()方法不允許重新分配最新的標準輸入流。
Syntax:
句法:
public static void setIn(InputStream set_in);
Parameter(s):
參數:
InputStream set_in – represents the latest standard input stream.
InputStream set_in –表示最新的標準輸入流。
Return value:
返回值:
The return type of this method is void, it does not return anything.
此方法的返回類型為void ,它不返回任何內容。
Example:
例:
// Java program to demonstrate the example of
// setIn () method of System Class
import java.lang.*;
import java.io.*;
public class SetInMethod {
public static void main(String[] args) throws Exception {
// Display file in a specific manner
System.setIn(new FileInputStream("E://Programs//getProperties().doc"));
// Read the first character in the file
char read_first_char = (char) System.in.read();
// Display first character of the File
System.out.println(read_first_char);
}
}
Output
輸出量
E:\Programs>javac SetInMethod.java
E:\Programs>java SetInMethod
J
翻譯自: https://www.includehelp.com/java/system-class-setin-method-with-example.aspx
system.setin