开发者

Input to a Java program - keyboard input v/s 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜