• Post Reply Bookmark Topic Watch Topic
  • New Topic

can't understand resirecting  RSS feed

 
rico yu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.*;
public class Redirecting{
public static void main(String[] args) throws IOException{
PrintStream console=System.out;
BufferedInputStream in=new BufferedInputStream(
new FileInputStream("ComboBoxTest.java"));
PrintStream out=new PrintStream(
new BufferedOutputStream(
new FileOutputStream("file1.txt")));
System.setIn(in);//1
System.setOut(out);//2
System.setErr(out);
*****BufferedReader br=new BufferedReader(
new InputStreamReader(System.in));
System.setOut(out);
String s;
while((s=br.readLine())!=null)
System.out.println(s);*****
out.close();
System.setOut(console);//3

}
}

here is some of my understandings(may be wrong ):
if sectence 1 and 2 wasn't in this program,when I run it,it should get something from my keyboard,and print in my screen
when add this two sentences,input will redirecting to ComboBoxTest.java
and output to file1.txt,and that between*** ***will take no use
I don't understand 3,it seems no use
need you advice
thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!