2012-03-19 67 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。