Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator

What is the System.setErr() function in Java?

Fouzia Bashir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The staticmethod accessible with class name System.setErr() function is used to reassign the standard error output stream.

Syntax


static void setErr(PrintStream error)

Parameters

  • error: the new standard error output stream.

Return value

This function does not return a value.

SecurityException: In this exception, the checkPermission() method does not allow the user to reassign the latest standard error output stream when the security manager exists.

Example

The code below demonstrates how the setErr() function works in Java.

// Load java input output package
import java.io.*;
// Main class
public class EdPresso {
public static void main(String[] args) throws FileNotFoundException {
OutputStream outst = new FileOutputStream("file1.txt");
PrintStream _printStream = new PrintStream(outst);
// set current standarad error output stream
System.setErr(_printStream);
System.out.println("Task completed!");
}
}

RELATED TAGS

java
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring