Java Java API
java.lang.System
public static void setIn(InputStream in)
Reassigns the "standard" input stream.
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)); }}
file exits: true-- reading from System.in --file one content