如何从url读取sqlite文件

时间:2010-10-14 13:43:51

标签: android sqlite

客户端给了我一个下载sqlite文件的URL。 我写下面的代码来读取sqlite文件,但我无法读取文件

`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);
        }
    }`

这段代码有什么错吗?或者有没有其他方法从url读取sqlite文件。?

请告诉我

由于

0 个答案:

没有答案