"హలో, అమిగో! ఈ రోజు మనం కొన్ని ఆసక్తికరమైన విషయాలను అన్వేషిస్తాము: System.in ఇన్‌పుట్ స్ట్రీమ్‌ని ఎలా భర్తీ చేయాలి ."

System.in  అనేది సాధారణ స్టాటిక్ ఇన్‌పుట్‌స్ట్రీమ్ వేరియబుల్, కానీ మీరు దానికి కొత్త విలువను కేటాయించలేరు. కానీ మీరు System.setIn() పద్ధతిని ఉపయోగించవచ్చు .

మొదట, మనం బఫర్‌ను సృష్టించాలి, ఆపై దానిలో కొన్ని విలువలను ఉంచాలి. ఆపై మేము ఇన్‌పుట్‌స్ట్రీమ్ ప్రోటోకాల్‌ని ఉపయోగించి బఫర్ నుండి డేటాను ఎలా చదవాలో తెలిసిన క్లాస్‌లో ర్యాప్ చేస్తాము.

ఇది ఇలా కనిపిస్తుంది:

కోడ్
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();
}

"బిలాబో! ఇది నేను చూసిన అత్యంత ఆసక్తికరమైన ఉదాహరణ. మీరు అలా చేయగలరని నాకు తెలియదు. ధన్యవాదాలు."

"మీకు స్వాగతం, అమిగో."