目录

static void setIn(InputStream in)

描述 (Description)

java.lang.System.setIn()方法重新分配“标准”输入流。

声明 (Declaration)

以下是java.lang.System.setIn()方法的声明

public static void setIn(InputStream in)

参数 (Parameters)

in - 这是新的标准输入流。

返回值 (Return Value)

此方法不返回任何值。

异常 (Exception)

SecurityException - 如果存在安全管理器且其checkPermission方法不允许重新分配标准输入流。

例子 (Example)

以下示例显示了java.lang.System.setIn()方法的用法。

package com.iowiki;
import java.lang.*;
public class SystemDemo {
   public static void main(String[] args) throws Exception {
      // existing file
      System.setIn(new FileInputStream("file.txt"));
      // read the first character in the file
      char ret = (char)System.in.read();
      // returns the first character
      System.out.println(ret);              
   }
} 

我们假设我们有一个文本文件file.txt ,其中包括 -

This is System class!!!

编译将产生以下结果 -

T
↑回到顶部↑
WIKI教程 @2018