Home » Java programming language

Java System class setIn() method with example

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

System class setIn() method

  • setIn() method is available in java.lang package.
  • setIn() method is used to assign again the standard input stream.
  • setIn() method is redirected because it does not read the input from the editor.
  • setIn() method read the input from the standard input stream.
  • setIn() method is a static method, it is accessible with the class name too.
  • setIn() method may throw an exception while reading the input from the standard input stream:
    SecurityException: In this exception checkPermission() method does not allow reassigning of the latest standard input stream when security manager exists.


    public static void setIn(InputStream set_in);


  • InputStream set_in – represents the latest standard input stream.

Return value:

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


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

import java.lang.*;

public class SetInMethod {
    public static void main(String[] args) throws Exception {

        // Display file in a specific manner
        System.setIn(new FileInputStream("E://Programs//getProperties().doc"));

        // Read the first character in the file
        char read_first_char = (char);

        // Display first character of the File


E:\Programs>java SetInMethod

Comments and Discussions




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

© some rights reserved.