(File export) What's going on with my code?[NEED HELP]

by Alaeddine Ghribi » Sun, 03 Apr 2011 08:26:53 GMT


Sponsored Links
 Hi,
I have data stored in a file in /data/data.... and i want to export it
to the SDCARD, i writed the code(wondering if it's correct) and the
class is not called, please try to help me to solve the problem, THANK
YOU:
public class Import extends Saves {
        private Context context;

        public void transfer(){
        context = getApplicationContext();
        File sdCard = Environment.getExternalStorageDirectory();
        File dir = new File (sdCard.getAbsolutePath() + "/SDCARD/Carburant/
storeddata.dat");
        dir.mkdirs();
        Toast.makeText(Import.this, "Test", Toast.LENGTH_SHORT).show();
        copyfile(context,"/data/data/carburant.android.com/files/",
                        sdCard.getAbsolutePath() + 
"/SDCARD/Carburant/storeddata.dat");

}

        private void copyfile(Context context,String srFile, String dtFile){
                context = getApplicationContext();
            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();
            }
          }

        }

-- 



Re: (File export) What's going on with my code?[NEED HELP]

by TreKing » Sun, 03 Apr 2011 09:28:56 GMT


 On Sat, Apr 2, 2011 at 7:26 PM, Alaeddine Ghribi




"The class is not called" ? Classes aren't "called". Can you clarify the
problem?

-------------------------------------------------------------------------------------------------
TreKing < http://sites.google.com/site/rezmobileapps/treking> ; - Chicago
transit tracking app for Android-powered devices

-- 


Sponsored Links


Re: (File export) What's going on with my code?[NEED HELP]

by Alaeddine Ghribi » Sun, 03 Apr 2011 09:40:43 GMT


 Well i have an export menu button, and when i tap on it, this class is
"executed", the normal way:
case R.id.importer:
                Intent i = new Intent(this,Import.class);
            startActivity(i);
                return true;

I have a problem in the Import class that i can't recognize it !





-- 



Re: Re: (File export) What's going on with my code?[NEED HELP]

by TreKing » Sun, 03 Apr 2011 10:55:50 GMT


 On Sat, Apr 2, 2011 at 8:40 PM, Alaeddine Ghribi





What does that mean?

-------------------------------------------------------------------------------------------------
TreKing < http://sites.google.com/site/rezmobileapps/treking> ; - Chicago
transit tracking app for Android-powered devices

-- 



Re: (File export) What's going on with my code?[NEED HELP]

by Alaeddine Ghribi » Sun, 03 Apr 2011 19:06:57 GMT


 Nothing happens when i tap in the menu option button "Export" !





-- 



Re: (File export) What's going on with my code?[NEED HELP]

by Alaeddine Ghribi » Sun, 03 Apr 2011 22:42:35 GMT


 I edited the code to a one more correct:
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/
storeddata.dat");
        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();
            }
          }

        }

I hope that it's correct, but how the code could be when tapping in
the "export" option menu?
I maked this and nothing happens:
case R.id.importer:
                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;

Thank you for your answer.






-- 



Re: (File export) What's going on with my code?[NEED HELP]

by Alaeddine Ghribi » Sun, 03 Apr 2011 23:06:42 GMT


  solved the half of the problem for now, however, i'm having a File
Not Found exception ! why the file is not copied ? How can i verify
the file in the SDCARD in the emulator ?
Thanks.

On 3 avr, 15:42, Alaeddine Ghribi <alaeddineghr...@gmail.com> wrote:

--



Re: (File export) What's going on with my code?[NEED HELP]

by Alaeddine Ghribi » Sun, 03 Apr 2011 23:39:45 GMT


  added a virtual SDCARD and the file is not exported ! I have a
storeddata.dat directory :\ ! Plus, i have a file not found exception
when tapping in the menu option "export" !
Any idea ?

On 3 avr, 16:06, Alaeddine Ghribi <alaeddineghr...@gmail.com> wrote:

--



Re: Re: (File export) What's going on with my code?[NEED HELP]

by Kostya Vasilyev » Mon, 04 Apr 2011 00:11:23 GMT


  think you are not creating a directory for the target file. Look up
File.mkdir and mkdirs.
03.04.2011 19:40 "Alaeddine Ghribi" <alaeddineghr...@gmail.com>
:
"/SDCARD/Carburant/
"/SDCARD/Carburant/
dtFile){
---------------------------------------------------------------------------
----------------------
Chicago

--



Re: (File export) What's going on with my code?[NEED HELP]

by Alaeddine Ghribi » Mon, 04 Apr 2011 00:20:28 GMT


 he directory is well created, but i have also storeddata is created
as a directiry too not as a file !
I'm trying also this code and same problem:
public void transfer(){

File sdCard = Environment.getExternalStorageDirectory();
File dir = new File (sdCard.getAbsolutePath() + "/SDCARD/
Carburant/");
dir.mkdir();
Toast.makeText(context, "Test", Toast.LENGTH_SHORT).show();
copyfile(context,nom,sdCard.getAbsolutePath() + "/SDCARD/Carburant/
storeddata.dat");

}

dir variable just creates the directiry to the saved file and cipyfile
func stores the data to the storeddata.dat file !

On 3 avr, 17:11, Kostya Vasilyev <kmans...@gmail.com> wrote:

--



Re: Re: (File export) What's going on with my code?[NEED HELP]

by TreKing » Mon, 04 Apr 2011 00:41:39 GMT


 On Sun, Apr 3, 2011 at 10:06 AM, Alaeddine Ghribi <alaeddineghr...@gmail.com




OK. From what?



I assume your FileNotFoundException has something to do with it.



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




Please Google "Java IO".

-------------------------------------------------------------------------------------------------
TreKing < http://sites.google.com/site/rezmobileapps/treking> ; - Chicago
transit tracking app for Android-powered devices

-- 



Re: (File export) What's going on with my code?[NEED HELP]

by Alaeddine Ghribi » Mon, 04 Apr 2011 01:46:26 GMT


 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.








-- 



Re: (File export) What's going on with my code?[NEED HELP]

by Alaeddine Ghribi » Mon, 04 Apr 2011 01:47:52 GMT


 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.






-- 



Re: (File export) What's going on with my code?[NEED HELP]

by Alaeddine Ghribi » Mon, 04 Apr 2011 08:08:56 GMT


 o 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:

--



Re: Re: (File export) What's going on with my code?[NEED HELP]

by TreKing » Mon, 04 Apr 2011 09:46:51 GMT


 On Sun, Apr 3, 2011 at 7:08 PM, Alaeddine Ghribi





Step through your code and figure out which one is throwing the exception,
for starters.

-------------------------------------------------------------------------------------------------
TreKing < http://sites.google.com/site/rezmobileapps/treking> ; - Chicago
transit tracking app for Android-powered devices

-- 



Other Threads

1. ALSA mixer,re-sampling code Vs Android Mixer,re-sampling code

Hi Sean et al,

I just have some questions related to Android Architecture for audio
(ECLAIR version).

a.Can we use the ALSA mixer(DMIX-i enabled in my system) for mixing
streams instead of android mixer?If yes then how?

b.Can we use re-sampler code of alsa instead of android re-sampler?

Why this facility of alsa not exploited or given the OEM's some way to
use their own code if they have better re-sampler and mixer codes
available through ALSA?????

Best Regards,
ani

2. 3 ROM Eclair released barengan !!!

Buat mana aja bro?

----------------------------------------
@acynx
ac...@ratjoendroid.com
Sent from my droid

----- Reply message -----
From: "widi dream" <wididr...@gmail.com>
Date: Fri, Jan 15, 2010 01:39
Subject: [id-android] 3 ROM Eclair released barengan !!!
To: "android groups" <id-android@googlegroups.com>

busyeett deh,,,,,
eclair, ada 3 ROM sekaligus keluar dg working camera!
dan ada langsung ada portnya untuk 32A ck...ck...ck.....

Salam -widi-
Powered by IPOT - The Best Online Trading in Indonesia

3. Problem reading/saving a preference

4. Data sharing between mobile users

5. Android Developer Needed - Atlanta

6. cocos2d for Android updated

7. creating random sizes of the emulator screen