Hi,
I want to store a file from internal storage to external storage
(sdcard) however, i'm facing a problem: here is the log message:
04-12 03:08:59.084: DEBUG/IOException(2059): No such file or directory

What's the problem?
Thank you for your help.


public void transfer(){
                try {
        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;

            try{
                final SharedPreferences preferences = PreferenceManager
                        .getDefaultSharedPreferences(context);
        String fileName =
context.getResources().getString(R.string.fileName);
        String fileDir = "" + preferences.getString("login", "") + "."+
preferences.getString("marque", "") + ".";

        File f2 = new File(context.getFilesDir(), fileDir+fileName);
    String y= f2.getAbsolutePath();
        Log.d("HI Export",y);
        InputStream in = new FileInputStream(f2);


        String destination = sdCard.getAbsolutePath()+"/Carburant/" +fileDir
+fileName;
    File fileCon = new File(destination);
    if( ! fileCon.exists() ){
            fileCon.createNewFile();
        }
            OutputStream out = new FileOutputStream(fileCon);




              byte[] buf = new byte[1024];
              int len;
              while ((len = in.read(buf)) != -1){
                out.write(buf, 0, len);
              }
              //out.flush();
              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();
                Log.d("IOException", e.getMessage());
            }
          }


        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;
        }
                }
        catch (Exception e) {
        Log.d("CARBURANT", e.getMessage());
        }

}
        }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to