Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8616899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:43:41+00:00 2026-06-12T05:43:41+00:00

in my android application I want to copy file from one directory to another

  • 0

in my android application I want to copy file from one directory to another , I have the path of file filePath , and have the path of directory dirPath in what I must copy the file. I tried many ways , but nothing helped , some ways only make some empty(0 kb) file with strange name different from the name of my file. SO help please 🙂

here is some part of code, if it help’s you, I have two buttons for Gallery and for Camera , and I must pick images from there

Button btnCam = (Button) dialog.findViewById(R.id.btncamera);
                btnCam.setOnClickListener(new View.OnClickListener() 
                {
                    @Override
                    public void onClick(View v) 
                    {
                        dialog.cancel();
                        Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                        startActivityForResult(cameraIntent, 2500);

                    }
                });
                //end of camera button 


                Button btnGal = (Button) dialog.findViewById(R.id.btngalary);
                btnGal.setOnClickListener(new OnClickListener() 
                {
                    @Override
                    public void onClick(View v) 
                    {
                        dialog.cancel();
                        Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        startActivityForResult(i, RESULT_LOAD_IMAGE);
                    }
                });

and Activity Result

@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) 
  {
      super.onActivityResult(requestCode, resultCode, data);

      if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) 
      {
          Uri selectedImage = data.getData();
          url = new String(selectedImage.toString()); 
          //here I must copy file with path `selectedImage` and replace it in 
          // directory with path `currentDir.hetPath()` 
      }
      if (requestCode == 2500) 
      {  
          Bitmap photo = (Bitmap) data.getExtras().get("data"); 
          imageView.setImageBitmap(photo);
          //here I must do the same thing above
      }  
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:43:42+00:00Added an answer on June 12, 2026 at 5:43 am

    I found some way , in my Activity result I must call copyFile(String, String) function , here is the body

    public static boolean copyFile(String from, String to) {
            try {
                File sd = Environment.getExternalStorageDirectory();
                if (sd.canWrite()) {
                    int end = from.toString().lastIndexOf("/");
                    String str1 = from.toString().substring(0, end);
                    String str2 = from.toString().substring(end+1, from.length());
                    File source = new File(str1, str2);
                    File destination= new File(to, str2);
                    if (source.exists()) {
                        FileChannel src = new FileInputStream(source).getChannel();
                        FileChannel dst = new FileOutputStream(destination).getChannel();
                        dst.transferFrom(src, 0, src.size());
                        src.close();
                        dst.close();
                    }
                }
                return true;
            } catch (Exception e) {
                return false;
            }
        } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create my Android virtual device from another java application. I don't
I have an application and i want to use Android Market License as copy
In my android application i want to copy the media images to another folder(in
I have an Android application with a Spinner and want to fill it dynamically
I want to create an Android application that show the sales report from SQL
I have PhoneGap-Android application and I want to check network connection type (No connection,
I want to create an android application which get data from sqlite database placed
I have downloaded an application from the android market. I just have to enter
I have an android application and want to save the state of instance in
I have a simple string with Chinese characters in my Android application and want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.