Home » Java programming language

Java System class setErr() method with example

System class setErr() method: Here, we are going to learn about the setErr() method of System class with its syntax and example.
Submitted by Preeti Jain, on September 15, 2019

System class setErr() method

  • setErr() method is available in java.lang package.
  • setErr() method is used to assign again the standard error output stream.
  • setErr() method is redirected because it does write anything in editor.
  • setErr() method writes the output to the proper JTextArea.
  • setErr() method is a static method, it is accessible with the class name too.
  • setErr() method may throw an exception while writing the error to the standard output stream:
    SecurityException: In this exception checkPermission() method does not allow reassigning of the latest standard error output stream when security manager exists.

Syntax:

    public static void setErr(PrintStream set_err);

Parameter(s):

  • PrintStream set_err – represents the latest standard error output stream.

Return value:

The return type of this method is void, it does not return anything.

Example:

// Java program to demonstrate the example of 
// setErr () method of System Class

import java.io.*;

public class SetErrMethod {
    public static void main(String[] args) throws Exception {
        OutputStream outputstream = new FileOutputStream("E://javasource//abc.txt");
        PrintStream printstream = new PrintStream(outputstream);
        System.setErr(printstream);
        System.out.println("File with no error");
    }
}

Output

E:\Programs>javac SetErrMethod.java
E:\Programs>java SetErrMethod
File with no error


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.