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.


    public static void setErr(PrintStream set_err);


  • 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.


// 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.out.println("File with no error");


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

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.