Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read failed: EBADF (Bad file number)

Tags:

android

When I try do a copy one file of the external storage for into folder database, this error happens:

java.io.IOException: read failed: EBADF (Bad file number)

This error happens on the line of while of this method

private void copiarBaseDados(InputStream input) throws IOException{
  OutputStream output = new FileOutputStream(ConfiguracoesBaseDados.BANCO_PATH + ConfiguracoesBaseDados.BANCO_NOME);
  int tamanho;
  byte[] buffer = new byte[1024];
  while ((tamanho = input.read(buffer)) > 0) 
       output.write(buffer, 0, tamanho);
  output.flush();
  output.close();
  input.close();
}

Any idea what could be the problem? Thanks

like image 660
Rodolfo Faquin Avatar asked Jan 29 '13 14:01

Rodolfo Faquin


1 Answers

Check whether your input(stream) exists before reading.

Also see if you have these permissons:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
like image 176
Govil Avatar answered Oct 15 '22 17:10

Govil