0

I am implementing my own DSL and using Xtend to generate codes. I need some static resources to be copied to my generate code. I was trying to use commons-io, but I couldn't get anywhere with that! What is the best way to do so? I am trying to avoid reading each file and writing to the corresponding file in output path...

AmirMV
  • 215
  • 1
  • 11

1 Answers1

1

This should do (taken from this web site, slightly modified, not tested)

def static void copyFileUsingChannel(File source, File dest) throws IOException {
    FileChannel sourceChannel = null;
    FileChannel destChannel = null;
    try {
        sourceChannel = new FileInputStream(source).getChannel();
        destChannel = new FileOutputStream(dest).getChannel();
        destChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
       }finally{
           sourceChannel.close();
           destChannel.close();
       }
}
JensG
  • 13,148
  • 4
  • 45
  • 55
  • I don't have a reference to destination file, all I have is an instance of IFileSystemAccess interface. – AmirMV Apr 27 '14 at 07:41
  • In that case you might add some more details to your question, especially what "static resources" exactly means for you. I assumed that we talk about some static files you know by name, but that's obviously not the case. – JensG Apr 27 '14 at 16:19