开发者

Input to a Java program - keyboard input v/s file

开发者 https://www.devze.com 2022-12-18 11:26 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号