Close

Java - System.setIn() Examples

Java Java API 


Class:

java.lang.System

java.lang.Objectjava.lang.Objectjava.lang.Systemjava.lang.SystemLogicBig

Method:

public static void setIn(InputStream in)

Reassigns the "standard" input stream.


Examples


package com.logicbig.example.system;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class SetInExample {

public static void main(String... args) throws IOException {

File file = new File("D:\\test\\one.txt");

System.out.println("file exits: "+file.exists());

FileInputStream stream = new FileInputStream(file);
System.setIn(stream);

System.out.println("-- reading from System.in --");

byte[] data = new byte[1000];
System.in.read(data);
System.out.println(new String(data));
}
}

Output

file exits: true
-- reading from System.in --
file one content ..




See Also