"์•ˆ๋…•ํ•˜์„ธ์š”, Amigo! ์˜ค๋Š˜ ์šฐ๋ฆฌ๋Š” System.in ์ž…๋ ฅ ์ŠคํŠธ๋ฆผ์„ ๊ต์ฒดํ•˜๋Š” ๋ฐฉ๋ฒ•๊ณผ ๊ฐ™์€ ๋ช‡ ๊ฐ€์ง€ ๋งค์šฐ ํฅ๋ฏธ๋กœ์šด ๋‚ด์šฉ์„ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค ."

System.in  ์€ ๊ฐ„๋‹จํ•œ ์ •์  InputStream ๋ณ€์ˆ˜์ด์ง€๋งŒ ๋‹จ์ˆœํžˆ ์ƒˆ ๊ฐ’์„ ํ• ๋‹นํ•  ์ˆ˜๋Š” ์—†์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ System.setIn() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค .

๋จผ์ € ๋ฒ„ํผ๋ฅผ ์ƒ์„ฑํ•œ ๋‹ค์Œ ์ผ๋ถ€ ๊ฐ’์„ ๋ฒ„ํผ์— ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ InputStream ํ”„๋กœํ† ์ฝœ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฒ„ํผ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ๊ณ  ์žˆ๋Š” ํด๋ž˜์Šค๋กœ ๋ž˜ํ•‘ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

์•”ํ˜ธ
public static void main(String[] args) throws IOException
{
 //Put data into a string
 StringBuilder sb = new StringBuilder();
 sb.append("Lena").append('\n');
 sb.append("Olya").append('\n');
 sb.append("Anya").append('\n');
 String data = sb.toString();

 //Wrap the string in a ByteArrayInputStream
 InputStream is = new ByteArrayInputStream(data.getBytes());

 //Replace in
 System.setIn(is);

 //Call an ordinary method that doesn't know about our changes
 readAndPrintLine();
}

public static void readAndPrintLine() throws IOException
{
 InputStreamReader isr = new InputStreamReader(System.in);
 BufferedReader reader = new BufferedReader(isr);

 while (true)
 {
  String line = reader.readLine();
  if (line == null) break;
  System.out.println(line);
 }
 reader.close();
 isr.close();
}

"Bilaabo! ์ด๊ฒƒ์€ ๋‚ด๊ฐ€ ๋ณธ ๊ฒƒ ์ค‘ ๊ฐ€์žฅ ํฅ๋ฏธ๋กœ์šด ์˜ˆ์ž…๋‹ˆ๋‹ค. ๋‹น์‹ ์ด ๊ทธ๋ ‡๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ๋ชฐ๋ž์Šต๋‹ˆ๋‹ค. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค."

"์ฒœ๋งŒ์—์š”, ์•„๋ฏธ๊ณ ."