Reputation: 1577
How do I specify options for Scala-IO library for appending files. The manual gives the following instructions:
import scalax.io.Resource._
import java.io.File
import scalax.io.{Seekable,Codec}
// see codec example for why codec is required
implicit val codec = Codec.UTF8
val someFile: Seekable = fromFile("someFile")
// write bytes
// By default the file write will replace
// an existing file with the new data
someFile.write (Array (1,2,3) map ( _.toByte))
// another option for write is openOptions which allows the caller
// to specify in detail how the write should take place
// the openOptions parameter takes a collections of OpenOptions objects
// which are filesystem specific in general but the standard options
// are defined in the OpenOption object
// in addition to the definition common collections are also defined
// WriteAppend for example is a List(Create, Append, Write)
someFile.write (List (1,2,3) map (_.toByte))
// write a string to the file
someFile.write("Hello my dear file")
// with all options (these are the default options explicitely declared)
someFile.write("Hello my dear file")(codec = Codec.UTF8)
// Convert several strings to the file
// same options fromString as for write
someFile.writeStrings( "It costs" :: "one" :: "dollar" :: Nil)
// Now all options
someFile.writeStrings("It costs" :: "one" :: "dollar" :: Nil,
separator="||\n||")(codec = Codec.UTF8)
How do I use the openOptions
?
Upvotes: 0
Views: 1107
Reputation: 170899
According to http://jesseeichar.github.io/scala-io-doc/0.4.3/api/index.html#scalax.io.Seekable,
The methods in scalax.io.Output are always fully destructive. IE write will replace all data in the file, insert, patch or append are your friends if that is not the behaviour you want
I.e. use append
, not write
. And Seekable.write
doesn't have openOptions
parameter. So the manual may be out-of-date here.
Upvotes: 2