2013-09-27 75 views
1

我使用了一些其他問題中提供的代碼,該代碼應該是正確的,我沒有理由懷疑它是否存在,但現在當我啓動應用程序我得到的是這樣的:將資產複製到SD卡時(使用assethelper)時出現java.io.IOException

java.io.IOException: An established connection was aborted by the software in your host machine 
at sun.nio.ch.SocketDispatcher.write0(Native Method) 
at sun.nio.ch.SocketDispatcher.write(Unknown Source) 
at sun.nio.ch.IOUtil.writeFromNativeBuffer(Unknown Source) 
at sun.nio.ch.IOUtil.write(Unknown Source) 
at sun.nio.ch.SocketChannelImpl.write(Unknown Source) 
at com.android.ddmlib.JdwpPacket.writeAndConsume(JdwpPacket.java:213) 
at com.android.ddmlib.Client.sendAndConsume(Client.java:642) 
at com.android.ddmlib.HandleHeap.sendREAQ(HandleHeap.java:348) 
at com.android.ddmlib.Client.requestAllocationStatus(Client.java:488) 
at com.android.ddmlib.DeviceMonitor.createClient(DeviceMonitor.java:835) 
at com.android.ddmlib.DeviceMonitor.openClient(DeviceMonitor.java:803) 
at com.android.ddmlib.DeviceMonitor.processIncomingJdwpData(DeviceMonitor.java:763) 
at com.android.ddmlib.DeviceMonitor.deviceClientMonitorLoop(DeviceMonitor.java:652) 
at com.android.ddmlib.DeviceMonitor.access$100(DeviceMonitor.java:44) 
at com.android.ddmlib.DeviceMonitor$3.run(DeviceMonitor.java:580) 

是用於複製從主要活動推出,是如下的方法:

private void copyAssets() 
{ 
    //iegust failu sarakstu 
    AssetManager assetManager = getAssets(); 
    String[] files = null; 
    try { 
     files = assetManager.list(""); 
    } catch (IOException e) { 
     Log.e("tag", "didnt get", e); 
    } 
    for(String filename : files) { 
     InputStream in = null; 
     OutputStream out = null; 
     try { 
      in = assetManager.open(filename); 
      File outFile = new File(getExternalFilesDir(null), filename); 
      out = new FileOutputStream(outFile); 
      copyFile(in, out); 
      in.close(); 
      in = null; 
      out.flush(); 
      out.close(); 
      out = null; 
      Log.d("tag","Success"); 
     } catch(IOException e) { 
      Log.e("tag", "Didnt copy: " + filename, e); 
     }  
    } 
} 
//kope failu 
private void copyFile(InputStream in, OutputStream out) throws IOException { 
    byte[] buffer = new byte[1024]; 
    int read; 
    while((read = in.read(buffer)) != -1){ 
     out.write(buffer, 0, read); 
    } 
} 
+0

許可「沒有理由懷疑它是」 < - 明明是你這叫做'異常' – blgt

+0

我的意思是一個黑猩猩寫的,他不知道自己在做什麼 – hexenbeast

+0

http://stackoverflow.com/questions/5618664/an-established-connection-was-aborted-by這個鏈接可能會幫助你 – guptakvgaurav

回答

0

你可以發表你的清單?你應該在以下權限添加到您的清單

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> 
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission> 
1

要在SD卡寫入文件,你必須給的清單

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
+0

我已經完成了。 – hexenbeast

+0

所以現在工作? –

+0

不,我已經做了,在我發佈這個問題之前。不幸的是,我還沒有找到問題。 – hexenbeast

相關問題