This is an excerpt from the Scala Cookbook, partially modified for the internet. This is Recipe 14.12, “How to prompt users for input from Scala shell scripts.”Back to top
You want to prompt a user for input from a Scala shell script and read her responses.Back to top
Console.read* methods to read user input, as demonstrated in the following script. Comments in the script describe each method:
A great thing about Scala is that not only is it scalable, it was also created to help you work on small tasks, including being useful in shell scripts. This includes small shell script tasks like prompting a user interactively from a shell script, and reading their input.
You can prompt users with print commands like
Java file FAQ: Can you share some examples of the Java BufferedReader class?
When it comes to reading character input streams, the Java BufferedReader class is extremely important, and I'll demonstrate this in several different source code examples.
Java file utilities FAQ: Do you have any Java file utilities you can share?
As I was working on another Java/Swing application this weekend, I ran across my "Java file utilities" class, and I thought I'd share that class here today. It's nothing too major, but it does include Java methods that let you open, read, write, and copy files using Java.
Ruby file FAQ: How do I open and read from a file in Ruby?
How many ways are there to open a file with Ruby and process the file contents? I don't know for sure, but here are two different ways to do it.
Ruby file processing, version 1
First, I'll use Ruby and the
File.open method to open a file and process its contents, like this:
Java command-line input FAQ: How can I read command-line input in a Java application?
Note: To see a more modern approach to this problem, see my article, How to read interactive command-line input in Java. That article demonstrates the use of the Java Scanner class, which came into existence as of Java 5.