2016-08-02 4 views
0

Как указать параметры для Scala-IO library для добавления файлов. manual дает следующие инструкции:Добавить файл с Scala-IO

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) 

Как используют openOptions?

ответ

2

Согласно http://jesseeichar.github.io/scala-io-doc/0.4.3/api/index.html#scalax.io.Seekable,

Методы в scalax.io.Output всегда полностью деструктивный. IE write заменит все данные в файле, вставить, исправить или добавить ваши друзья, если это не то, что вы хотите

I.e. использование append, нет write. И Seekable.write не имеет openOptions параметр. Поэтому руководство может быть устаревшим.

Смежные вопросы