views:

168

answers:

1

I have a Java program that accepts input text typed in from standard input

is there a way to find if the user has typed in the text or redirected input from a file?

$ java prog this text is typed in from the keyboard

$ java prog < file.txt

Thanks!

A: 

Judging from the JLine source code, you have to use JNI to make native OS calls to determine whether stdin is a TTY. If you're certain to be in a Unix-like environment, you can do what they do there.

Jonathan Feinberg
Thank you Jonathan..
Kedar