« Return to Thread: FileExtras.copyTo() appears to be broken

Re: FileExtras.copyTo() appears to be broken

by Jamie Webb-2 :: Rate this Message:

Reply to Author | View in Thread

On 2008-04-18 17:01:09 Andrew O'Malley wrote:

> Hi all,
>
> I just attempted to copy a file using:
>
> import scalax.io.Implicits._
> import java.io.File
>
> object App extends Application {
>    new File("/Users/andrew/books.txt").copyTo(new
> File("/Users/andrew/ backup-books.txt"))
> }
>
> And get the following exception:
> Caused by: java.io.FileNotFoundException: /Users/andrew/backup-
> books.txt (No such file or directory)
>
> Note: it's complaining about the destination file not existing, not  
> the source file.
>
> The problem appears to be that the copy method uses
> FileExtras.channel to copy the file. The channel created is always
> from a FileInputStream, but in the case of copy the destination
> should be a channel from a FileOutputStream.
>
> See:
> http://hg.scalaforge.org/scalax/general/file/05bdf43a3449/src/scalax/io/files.scala
>
> Maybe a new method, outChannel, should be added to get the channel  
> from a FileOutputStream and copy changed to use it for the
> destination file. (And maybe channel should be renamed to inChannel
> for consistency)

Fixed. Thanks for the report.

> As an aside, what JVM is scalax supposed to be targetting? AFAIK,  
> channels are JDK 1.5+ only.

Yes, we're targeting JVM 1.5.

Cheers

/J

 « Return to Thread: FileExtras.copyTo() appears to be broken