Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

android - read failed: EBADF (Bad file number)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...