System.setErr() in Java

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

Syntax:

void java.lang.System.setErr(PrintStream err)

This method takes one argument of type PrintStream as its parameter. This method reassigns the "standard" error output stream. First, if there is a security manager.

Parameters: One parameter is required for this method.

err the new standard error output stream.

Throws:

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

Approach

Java

import java.io.PrintStream;

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

        PrintStream err = null;
        System.setErr(err);

        System.out.println("Successfully sets the error");
    }
}

Output:

Successfully sets the error


No comments:

Post a Comment