Java tutorial
import java.io.ByteArrayInputStream; import java.util.Scanner; public class Main { public static void main(String[] args) { String str = "java2s.com"; ByteArrayInputStream bais = new ByteArrayInputStream(str.getBytes()); System.setIn(bais); Scanner scanner = new Scanner(System.in); String input = scanner.next(); System.out.println(input); } }