views:

22

answers:

0

Hi all

Client given me an url to download sqlite file. I written following code to read sqlite file bt im not able to read file

`public void DownloadFromUrl(String sqlFileURL) {
        try {
            HttpURLConnection httpCon = null;
            InputStream myInput = null;
            URL url = new URL(sqlFileURL);
            long startTime = System.currentTimeMillis();

            httpCon = (HttpURLConnection) url.openConnection();
            httpCon.setRequestMethod("GET");
            httpCon.setDoOutput(true);

            myInput = httpCon.getInputStream();
            int status = httpCon.getResponseCode();
            if (status == HttpURLConnection.HTTP_OK) {
                myInput = httpCon.getInputStream();
            }

            String outFileName = DB_PATH + DB_NAME;
            OutputStream myOutput = new FileOutputStream(outFileName);

            byte[] buffer = new byte[1024];
            int length;
            while ((length = myInput.read(buffer)) > 0) {
                myOutput.write(buffer, 0, length);
            }

            myOutput.flush();
            myOutput.close();
            myInput.close();

            Log.d(TAG, "download ready in"
                    + ((System.currentTimeMillis() - startTime) / 1000)
                    + " sec");

        } catch (IOException e) {
            Log.d(TAG, "Error: " + e);
        }
    }`

is there any mistake in this code?. or is there any other way to read sqlite file from url.?

Please let me know

Thanks