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 4273272
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:41:25+00:00 2026-05-21T07:41:25+00:00

I’m facing a problem when copying a file in the external sdcard: here is

  • 0

I’m facing a problem when copying a file in the external sdcard:
here is what i get in the log message:

04-06 17:52:36.804: DEBUG/Carburant(258): Sdcard can read/write !!
04-06 17:52:36.864: DEBUG/Carburant(258): /mnt/sdcard/mnt/sdcard/settings.dat (No such file or directory)

And here is my code:

public class Import {
    private Context context;
    private String nom;


    public Import(Context context,String nom) {
        this.context = context;
        this.nom=nom;
       }

    public void transfer(){

    File sdCard = Environment.getExternalStorageDirectory();
    boolean mExternalStorageAvailable = false;
    boolean mExternalStorageWriteable = false;
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
        // We can read and write the media
        Log.d("Carburant", "Sdcard can read/write !!" ); 
        mExternalStorageAvailable = mExternalStorageWriteable = true;
        File root = Environment.getExternalStorageDirectory();
        File nmea_file = new File(root,"settings.dat");
        copyfile(nom,sdCard.getAbsolutePath() + nmea_file);
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        // We can only read the media
        Log.d("Carburant", "Sdcard only read !!" ); 
        mExternalStorageAvailable = true;
        mExternalStorageWriteable = false;
    } else {
        // Something else is wrong. It may be one of many other states, but all we need
        //  to know is we can neither read nor write
        mExternalStorageAvailable = mExternalStorageWriteable = false;
    }

And here is my copyfile func:

private void copyfile(String srFile, String dtFile){
        try{
            File f1 = new File(srFile);
            File f2 = new File(dtFile);
          InputStream in = new FileInputStream(f1);
          OutputStream out = new FileOutputStream(f2);

          byte[] buf = new byte[1024];
          int len;
          while ((len = in.read(buf)) > 0){
            out.write(buf, 0, len);
          }
          in.close();
          out.close();
          Toast.makeText(context, "Export effectu�", Toast.LENGTH_SHORT).show();
        }
        catch(FileNotFoundException ex){
            Toast.makeText(context, "File Not found", Toast.LENGTH_SHORT).show();
            String x=ex.getMessage();
            Log.d("Carburant", x);
        }
        catch(IOException e){
            Toast.makeText(context, "Echec", Toast.LENGTH_SHORT).show();      
        }
      }

i don’t know why the compiler gives /mnt/sdcard/mnt/sdcard/settings.dat as output file, there is duplicate in the /mnt/sdcard…
Thank you for your help.

File dir = new File (sdCard.getAbsolutePath() + "/Carburant/");
        dir.mkdirs();
        File file = new File(dir, "settings.dat");
        copyfile(nom,dir.getAbsolutePath());
  • 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-05-21T07:41:25+00:00Added an answer on May 21, 2026 at 7:41 am

    Try using:

    copyfile(nom, nmea_file.getAbsolutePath());
    

    instead.

    You are getting one "/mnt/sdcard" from the root variable and another one from the sdCard variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.