Here's a snippet from my sample pack installers

in my installers I have assets in a folder called "samples"


private void CopyFiles(String dir)
    {

        try
        {
                String [] filelist = am.list("samples/" + dir);

                for (int count = 0; count < filelist.length; count++)
                {

                        if (WasError == true) break;


                        String currfile = filelist[count];

                        AssetFileDescriptor af = am.openFd("samples/" + dir + 
"/" +
currfile);
                        long filesize = af.getLength();
                        InputStream is = am.open("samples/" + dir + "/" + 
currfile,
am.ACCESS_BUFFER);

                        byte [] tempdata = new byte[(int)filesize];

                        is.read(tempdata);


                        is.close();

                        if (IsNewVersion == true)
                        {
                                File outfile = new 
File("/sdcard/electrum/samples/" +
PACK_NAME + "/" + dir,currfile);
                                outfile.createNewFile();

                                FileOutputStream fo = new 
FileOutputStream(outfile);
                                fo.write(tempdata);
                                fo.close();
                        }
                        else
                        {
                                File outfile = new File("/sdcard/electrum/
samples/",currfile);
                                outfile.createNewFile();

                                FileOutputStream fo = new 
FileOutputStream(outfile);
                                fo.write(tempdata);
                                fo.close();

                        }

                }


        }

        catch(Exception e)
        {
                WasError = true;

        ErrMessage = e.getMessage();

                PostHandler.post(ShowMsg);
                PostHandler.post(DoneMsg);

        }

    }


-niko

On Oct 8, 6:29 am, androidinsider <[email protected]> wrote:
> hey guys, i hope this is the right forum.
>
> what i am trying to do is simply copy over entire folder full of mp3
> files onto sdcard within an app. I am doing this out of "assets"
> folder because raw folder does not allow mp3 files to be named the way
> i need them to.
>
> here is what I dug up so far but not sure if this will work. i am lost
>
> InputStream ins = getResources().getAssets().open("");
> int size = ins.available();
> // Read the entire resource into a local byte buffer.
> byte[] buffer = new byte[size];
> ins.read(buffer);
> ins.close();
> FileOutputStream fos = new FileOutputStream("/sdcard/myfolder/");
> fos.write(buffer);
> fos.close();
>
> can someone help?
--~--~---------~--~----~------------~-------~--~----~
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