If I have my druthers, I’ll finish writing my current book near this wonderful spot, somewhere in Alaska.
As shown in the image, I’ve finally come to the realization that I can’t write a book. But I can write a few sentences, and then a few pages, and eventually a chapter on a given topic. And then I can write another chapter, and then another. But to sit down and say, “I’m going to write a book,” no, that’s too hard.
“The best work that anybody ever writes is the work that is on the verge of embarrassing him, always.” Good advice on writing from Arthur Miller, via the Twitter account of Jon Winokur.
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 12.3, “How to read and write binary files in Scala.”
You want to read data from a binary file or write data to a binary file.
Scala doesn’t offer any special conveniences for reading or writing binary files, so use the Java
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
I was working with Android Preferences recently, and after writing a few “save my preference” methods, I decided to take a few minutes to organize my code and put all of those Preference methods in a PreferenceUtils class. I made the methods static, and following functional programming principles, I made their output depend only on their input, so they require you to pass in a
Context reference, along with your preference key and value.
I’m currently writing a complicated Linux bash shell script where I need to keep a counter in an external file, and to do so, I need to be able to write to a file and then read from that file.
In short, this is how I write my counter to that file:
# create a variable to represent the filename COUNTER_FILE="counter.tmp" # write to the file echo "0" > $COUNTER_FILE
Later in the code I increment the counter and write it to the file like this:
Problem: You want to write XML data to a file in a Scala application, such as saving application data or configuration information to a file.
scala.xml.XML.save method to write a Scala literal to a file. Given this XML literal:
PHP STDERR FAQ - How do I write to STDERR in a PHP script, specifically a PHP command line script?
I've written a lot of my command line scripts in PHP lately, and I just ran across this problem in my own script, how to write to STDERR in PHP. Fortunately the solution is easy, just use the PHP fwrite function like this:
fwrite(STDERR, “hello, world\n”);
Or, in a more real-world example, here's how I'm writing MySQL error messages to STDERR in PHP:
Perl write to file FAQ: Can you demonstrate an example of how to write to a file in Perl?
Somehow I managed to go all these years without showing a simple Perl "write to file" example. Let's fix that.
Perl “write to file” example
Here's a short snippet of code that shows how to write to a file in Perl: