fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.io.File;
  7. import java.io.FileInputStream;
  8. import java.io.FileOutputStream;
  9. import java.io.IOException;
  10. import java.io.InputStream;
  11. import java.io.OutputStream;
  12. import java.nio.channels.FileChannel;
  13. import java.nio.file.Files;
  14. import java.nio.file.StandardCopyOption;
  15. import java.text.SimpleDateFormat;
  16. import java.util.Date;
  17. import java.util.concurrent.TimeUnit;
  18.  
  19. /* Name of the class has to be "Main" only if the class is public. */
  20. class Ideone
  21. {
  22. public static void main (String[] args) throws java.lang.Exception
  23. {
  24. // your code goes here
  25. }
  26.  
  27. private static void copyWithChannel(File source, File target) throws IOException {
  28.  
  29. FileInputStream in = new FileInputStream(source);
  30.  
  31. FileChannel inChannel = in.getChannel();
  32. FileChannel outChannel = out.getChannel();
  33.  
  34. inChannel.transferTo(0, source.length(), outChannel);
  35.  
  36. in.close();
  37. out.close();
  38.  
  39. }
  40.  
  41. private static void copyWithFiles(File source, File target) throws IOException {
  42.  
  43. Files.copy(source.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING);
  44. }
  45.  
  46. private static void copyWithStream(File source, File target) throws IOException {
  47.  
  48. InputStream in = new FileInputStream(source);
  49. OutputStream out = new FileOutputStream(target);
  50. byte[] buf = new byte[8192];
  51. int len;
  52. while ((len = in.read(buf)) > 0) {
  53. out.write(buf, 0, len);
  54. }
  55. in.close();
  56. out.close();
  57. }
  58. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
Standard output is empty