Is it better to use import scala.reflect.io.File or java.io.File in Scala?

后端 未结 3 1236
渐次进展
渐次进展 2020-12-20 16:22

I see the scala.reflect.io.File class, is this supposed to help with file operations? Am I supposed to prefer to use this rather than java.io.File? What is the purpose of th

3条回答
  •  执念已碎
    2020-12-20 16:30

    java.io.File is what you should use in general.

    scala.reflect.io.File can be used for file operations. Code using it idiomatic for scala than using Java's File class. This is because it uses other scala classes such as scala.io.Codec and scala.Option and utilizes scala features such as implicit parameter. However, it is not (and may never be) considered ready for general use.

    According to the source for scala.reflect.io.File (github):

    /**
    * ''Note: This library is considered experimental \
         and should not be used unless you know what you are doing.''
    */
    

    If you know what you are doing or are just wanting to experiment (and do not care if things don't work or break in the future) then you may decide to use scala.reflect.io.File. If you do decide to use it, the source code looks well documented with ScalaDoc comments.

提交回复
热议问题