So here is the code(not working yet):
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();
        File dir = new File (sdCard.getAbsolutePath() + "/SDCARD/
Carburant/");
        dir.mkdirs();
        Toast.makeText(context, "Test", Toast.LENGTH_SHORT).show();
        copyfile(context,nom,sdCard.getAbsolutePath() + "/SDCARD/Carburant/
storeddata.dat");

}

        private void copyfile(Context context,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();
            }
            catch(IOException e){
                Toast.makeText(context, "Echec",
Toast.LENGTH_SHORT).show();
            }
          }

        }

It shows me File Not Found, my question is the file is not found in
the /SDCARD or in the /data/data/... ?

On 3 avr, 18:46, Alaeddine Ghribi <alaeddineghr...@gmail.com> wrote:
> I copied the apk to my phone, and when i tap in the menu button
> "export", same problem! Plus the directory is not created(in the
> Simulator yes the direc is created)!
> Here is the menu button export code:
> 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;
>
> Is that correct ? Thank you for verifying it.
>
> On 3 avr, 17:41, TreKing <treking...@gmail.com> wrote:
>
>
>
>
>
>
>
> > On Sun, Apr 3, 2011 at 10:06 AM, Alaeddine Ghribi <alaeddineghr...@gmail.com
>
> > > wrote:
> > > I solved the half of the problem for now, however, i'm having a File Not
> > > Found exception !
>
> > OK. From what?
>
> > > why the file is not copied ?
>
> > I assume your FileNotFoundException has something to do with it.
>
> > > How can i verify the file in the SDCARD in the emulator ?
>
> > You can use the File Explorer tool to navigate the emulator contents.
>
> > On Sun, Apr 3, 2011 at 11:20 AM, Alaeddine Ghribi <alaeddineghr...@gmail.com
>
> > > wrote:
> > > The directory is well created, but i have also storeddata is created as a
> > > directiry too not as a file !
>
> > Please Google "Java IO".
>
> > --------------------------------------------------------------------------- 
> > ----------------------
> > TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
> > transit tracking app for Android-powered devices

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

Reply via email to