我的Android应用程序中有一个要求.我需要以编程方式下载并保存SD卡特定文件夹中的文件.我开发了源代码,这是
String DownloadUrl = "http://myexample.com/android/";
     String fileName = "myclock_db.db";
    DownloadDatabase(DownloadUrl,fileName);
    // and the method is
public void DownloadDatabase(String DownloadUrl, String fileName) {
    try {
        File root = android.os.Environment.getExternalStorageDirectory();
        File dir = new File(root.getAbsolutePath() + "/myclock/databases");
        if(dir.exists() == false){
             dir.mkdirs();  
        }
        URL url = new URL("http://myexample.com/android/");
        File file = new File(dir,fileName);
        long startTime = System.currentTimeMillis();
        Log.d("DownloadManager" , "download url:" +url);
        Log.d("DownloadManager" , "download file name:" + fileName);
        URLConnection uconn = url.openConnection();
        uconn.setReadTimeout(TIMEOUT_CONNECTION);
        uconn.setConnectTimeout(TIMEOUT_SOCKET);
        InputStream is = uconn.getInputStream();
        BufferedInputStream bufferinstream = new …