-1

I want to change the default input and output for a Java program to some custom input or output stream.

The main purpose is I want to redirect all the outputs and inputs to a socket connection, but the original code just reads from and writes to standard input output stream (System.in & System.out)

Note: The original code is too big to manually change it to output to the Socket.

I do not want to dump unnecessary code here, so please don't vote to close for "Needs details or clarity" please ask for the code part if you need it and for any other details!

Mark Rotteveel
  • 82,132
  • 136
  • 114
  • 158
Jaysmito Mukherjee
  • 1,272
  • 5
  • 21
  • As Expected! Please at least comment the reason you are voting to close! – Jaysmito Mukherjee Apr 08 '21 at 10:41
  • If you expected it then you don't need a comment to tell you why. Regardless, you should read how to provide a [mre] for your question. We shouldn't have to ask for the information we need to be able to provide answers. We're all volunteers here and it seems a waste of our time to leave comments on every question asking for them to provide enough detail. – Henry Twist Apr 08 '21 at 12:38
  • @HenryTwist by common sense what minimal example do you expect for this question? Please don't follow the textual rules blindly! There are many clear questions without any such example! For example :- https://stackoverflow.com/questions/1200621/how-do-i-declare-and-initialize-an-array-in-java?rq=1 https://stackoverflow.com/questions/215497/what-is-the-difference-between-public-protected-package-private-and-private-in?rq=1 etc so please use your common sense – Jaysmito Mukherjee Apr 08 '21 at 12:45
  • Maybe some code you've tried, research you've done etc? I'm not going to argue with you here about it, I wasn't the one who voted originally anyway, I was just providing you an opinion. However by adding that note in your question, you're effectively telling us that you haven't provided all the information we need. You're inviting people to close your question. – Henry Twist Apr 08 '21 at 12:57
  • Also I never commented on the questions you linked. There's plenty of content on Stack Overflow that isn't on topic etc, but that doesn't mean we should encourage more. – Henry Twist Apr 08 '21 at 12:58

1 Answers1

0

Try this:

System.setIn(someInputStream);
System.setErr(somePrintStream);
System.setOut(somePrintStream);
Dave The Dane
  • 444
  • 3
  • 10