2012-09-02 40 views

回答

2

將文件添加到您的資源/原始目錄。當應用程序運行時,您可以檢查目標文件的存在。如果不存在,請不要寫在存儲根目錄下!unpack and write to the SD card

File dest = Environment.getExternalStorageDirectory(); 
InputStream in = context.getResources().openRawResource(R.raw.file); 
// Used the File-constructor 
OutputStream out = new FileOutputStream(new File(dest, "file.zip")); 

// Transfer bytes from in to out 
byte[] buf = new byte[1024]; 
int len; 
try { 
    // A little more explicit 
    while ((len = in.read(buf, 0, buf.length)) != -1){ 
     out.write(buf, 0, len); 
    } 
} finally { 
    // Ensure the Streams are closed: 
    in.close(); 
    out.close(); 
} 
+0

請不要寫在存儲根目錄下!使用:/ Android/data//files /請參閱:http://developer.android.com/guide/topics/data/data-storage.html#filesExternal –

相關問題