system.setin_Java System类setIn()方法及示例

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值