I want to copy a file from /data/data... to the external SDCARD! However, i'm finding this problem: Log message: 04-04 12:01:19.271: DEBUG/Carburant(9623): /username.usercar.settings.dat (No such file or directory)
I guess that i can't simply access to this file without an "extra" code. Here is my code(the necessary lines):
File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/Carburant/");
dir.mkdirs();
copyfile(nom,sdCard.getAbsolutePath() + "/Carburant/storeddata.dat");
public Import(Context context,String nom) {
this.context = context;
this.nom=nom;
}
The lines where the function is called:
case R.id.exporter:
final SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(context);
String fileName = getResources().getString(R.string.fileName);
fileDir = "" + preferences.getString("login", "") + "."+ preferences.getString("marque", "") + ".";
Import myImport = new Import(this,fileDir+fileName);
myImport.transfer();
return true;
Android Manifest(necessary code):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="carburant.android.com"
android:versionCode="1" android:versionName="0.1">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk android:minSdkVersion="8" />
Copy file 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[4096];
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();
}
}
So, what misses? Thanks.