伙计我在我的URL中有一个文本文件。单击一个按钮我可以将它下载到SD卡。将文件从URL替换到原始文件夹
但我需要用原始文件夹中的文件替换下载的文件。两者都是不同的文件。
这是怎么了我是从网址
File sdcard = Environment.getExternalStorageDirectory();
File dir = new File (sdcard.getAbsolutePath() + "/varun");
dir.mkdirs();
try {
u = new URL("http://hihowru.com/123.xml");
file = new File(dir,"123.xml");
startTime = System.currentTimeMillis();
Log.d("DownloadManager", "download begining");
Log.d("DownloadManager", "download url:" + url);
Log.d("DownloadManager", "downloaded file name:" + "a.mp3");
URLConnection uconnection = u.openConnection();
InputStream is = uconnection.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
baf = new ByteArrayBuffer(5000);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
FileOutputStream fos;
fos = new FileOutputStream(file);
fos.write(baf.toByteArray());
fos.flush();
fos.close();
Toast toast = Toast.makeText(getApplicationContext(), "Downloaded to Sdcard/varun"+audioxml, 0);
toast.show();
Log.d("DownloadManager", "download ready in" + ((System.currentTimeMillis() - startTime)/1000) + " sec");
Intent ii = new Intent(DownloadFiles.this,Relaxation.class);
startActivity(ii);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
下载,但我需要替换该文件(下载的文件),在原始文件夹中的文件
下载文件名:hi.txt 原始文件夹名称:hw.txt
如何达致这,请帮助
http://stackoverflow.com/questions/5178873/how-to-overwrite-a-text-file-programmatically,有一个职位重写你可以参考这个 – Triode 2012-03-01 11:01:21