2012-03-19 85 views
0

我想知道如何从URL获取文件名,以便它可以下载到SDCARD而不覆盖新文件。来自URL的文件名(覆盖)

int lenghtOfFile = conexion.getContentLength(); 
Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile); 
String fileName = "test.epub"; 
InputStream input = new BufferedInputStream(url.openStream()); 
OutputStream output = new FileOutputStream("/sdcard/"+ fileName); 

回答

0

将数据写入到SD卡

File sdcard = Environment.getExternalStorageDirectory(); 
     File f = new File(sdcard, "/yourfile"); 

if(!f.exsist()){ 
f.createNewFile(); 
//Use outwriter here, outputstream search how to write into a tet file in java code 
} 

使用随机为每个文件的名称,创建一个唯一的ID。