title: Copy/paste and creating folder in android
body: <p>I want to copy file from one folder to the other folder (for example : sdcard0/folder1/a.text  to sdcard0/folder2 ). I have seen a lot of sample code in this site and other sites but non of them work for me . I don't know where is my problem. I also add permission to the manifest file.
  what should I do?
  I have several method for this, that I named them from copy1 to copy3 .</p>
  
  <pre><code>      //----------Method 1
   public void copy1(File src, File dst) throws IOException {
      InputStream in = new FileInputStream(src);
      OutputStream out = new FileOutputStream(dst);
  
      // Transfer bytes from in to out
      byte[] buf = new byte[1024];
      int len;
      while ((len = in.read(buf)) &gt; 0) {
          out.write(buf, 0, len);
      }
      in.close();
      out.close();
  }
  
   //----------Method 2
  public void copy2(File src, File dst) throws IOException {
      FileInputStream inStream = new FileInputStream(src);
      FileOutputStream outStream = new FileOutputStream(dst);
      FileChannel inChannel = inStream.getChannel();
      FileChannel outChannel = outStream.getChannel();
      inChannel.transferTo(0, inChannel.size(), outChannel);
      inStream.close();
      outStream.close();
  }
  
   //----------Method 3
      public static boolean copy3(File source, File dest){
      try{
              // Declaration et ouverture des flux
              java.io.FileInputStream sourceFile = new java.io.FileInputStream(source);
  
              try{
                      java.io.FileOutputStream destinationFile = null;
  
                      try{
                              destinationFile = new FileOutputStream(dest);
  
                              // Lecture par segment de 0.5Mo
                              byte buffer[] = new byte[512 * 1024];
                              int nbLecture;
  
                              while ((nbLecture = sourceFile.read(buffer)) != -1){
                                      destinationFile.write(buffer, 0, nbLecture);
                              }
                      } finally {
                              destinationFile.close();
                      }
              } finally {
                      sourceFile.close();
              }
      } catch (IOException e){
              e.printStackTrace();
              return false; // Erreur
      }
  
      return true; // Résultat OK
  </code></pre>
  
  <p>}</p>
  
  <p>and I use them like this:
                  String path=Environment.getExternalStorageDirectory().toString();
                  File f= new File(path +"/folder1/a.txt");
                  File f2= new File(path+"/folder2/" );
                  try{
                    copy1(f,f2);
                  }
                  catch(Exception e){}</p>
  
  <p>and also for creating Directory  :</p>
  
  <pre><code>File root = android.os.Environment.getExternalStorageDirectory(); 
              File dir = new File (root.getAbsolutePath() + "/AAAli");
              if(!dir.exists()) {                                 
                  dir.mkdirs(); // build directory
              }
  </code></pre>