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!
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.
精彩评论