• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to programmatically 'System.in'?  RSS feed

 
Pakawat Gibson LP
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to send input text by hardcoding it if it's supposed to get from the keyboard?

Thanks
:-)
 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Javaranch,

what do you mean by "hardcoding", if you mean to read from the file OR write the input command into your java file then you can use simple String or String array for multiple commands.

and this might help.
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.setIn(Inputstream in) allows reassigning the standard input stream to anything what you need.

Other way is to put the input into file and use OS redirection by running the program like this
 
Pakawat Gibson LP
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works!

Thanks for your helping hands and for the great forum like this
 
Ankit Garg
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you know the file to be used as input before executing the program, then you can also use input redirection,
java programName < file.txt

I think you must already be knowing about this but I thought it might come in handy at times....
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!