2012-08-28 105 views
0

我想上傳一個文件(大小爲20MB)上傳大文件,但在上傳,logcat的顯示的Android NDK:通過NDK

內存溢出異常

所以我認爲爲此使用NDK。但我不知道如何繼續。所以幫助我

static int chunkSize = 512; 
static final  byte[] chunks = new byte[chunkSize]; 
..... 
...... 
while (true) 
    { 
    synchronized (chunks) 
    { 
     int amountRead = fileInputStream.read(chunks); 
     System.out.println("========amount read========="+amountRead); 
     if (amountRead == -1) 
     { 
     break; 
     } 
     bufferOutputStream.write(chunks, 0, amountRead); 
     bufferOutputStream.flush(); 
    } 
    } 

回答

0

當你上傳時,你需要使用InputStream而不是將整個文件加載到內存中。

+0

IAM使用「的FileInputStream」讀書「byteoutputstream」寫 – Sudarshan

+0

那麼也許你的HTTP上傳收作方法初探加載整個字節數組到內存 –

+0

我已經編輯我的問題,與我片段檢查have..plz和y錯誤即將到來 – Sudarshan