Log in or register to post comments

How to load dataset from internal or external storage?

July 4, 2018 - 6:03am #1

Hi guys,

I have been stuck with the Dataset loading problem for several days.I know that xml files can be loaded from Android internal or external storage ,but I don't know how to write the path.Every storage type I had tried but none of them worked .Please help me !!!

Here is my code:

......

copy(mDatasetString);

if (!mDataset.load("storage/sdcard/"+mDatasetString,

                STORAGE_TYPE.STORAGE_APP)){

            Log.d("DBload", "doLoadTrackersData: failed to load Dataset");

            return false;}

......

 

public void copy(String datasetName){

        try {

            String xml=null;

            InputStream inputStream = getAssets().open(datasetName);

            byte[] bytes = new byte[1024];

            ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();

            while (inputStream.read(bytes) != -1) {

                arrayOutputStream.write(bytes, 0, bytes.length);

            }

            arrayOutputStream.close();

            xml = new String(arrayOutputStream.toByteArray());

            String dir= "storage/sdcard/";

            FileOutputStream openFileOutput = new FileOutputStream(dir+datasetName);

            openFileOutput.write(xml.getBytes());

            openFileOutput.flush();

            inputStream.close();

            openFileOutput.close();

        }

        catch(IOException e){

            e.printStackTrace();

        }

    } 

 

I have added the users permission.

And the dialog still tell me that "Failed to load trackers data!" and logcat has message "doLoadTrackersData: failed to load Dataset".

Please help me if I missed something !

Log in or register to post comments