System.setIn() in Java

System.setIn(): This method is available in java.lang.System class of Java.

Syntax:

void java.lang.System.setIn(InputStream in)

Reassigns the "standard" input stream.

Parameters: One parameter is required for this method.

in: the new standard input stream.

Throws:

1. SecurityException - if a security manager exists and its checkPermission method doesn't allow reassigning of the standard input stream.

Approach

Java

import java.io.InputStream;

public class SystemsetIn {
    public static void main(String[] args) {

        InputStream in = InputStream.nullInputStream();
        System.setIn(in);

        System.out.println("Successfully sets InputStream");
    }
}

Output:

Successfully sets InputStream


No comments:

Post a Comment