How to write text files in Scala

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 12.2, “How to write text files in Scala.”


You want to write plain text to a file, such as a simple configuration file, text data file, or other plain-text document.


Scala doesn’t offer any special file writing capability, so fall back and use the Java PrintWriter or FileWriter approaches:

A Java class that writes to and reads from a remote socket

I'm not going to describe this much today, but here's the source code for a Java class I put together from a number of other sources on the internet. In short, this code uses a Java Socket to connect to a port on a remote server, sends a command to that server to be executed, and then reads the output from the command that is executed. As a result, I assume that all information sent is text (nothing binary).