i have error
java.io.ioexception: read failed: ebadf (bad file number)
on line of code:
while ((input = fis.read(buffer)) != -1) {
what think cause ebadf bad file number error on line? ideas on how fix it. wanted working stream read in pdf file sd , read put on sd card again different name.
stack trace
07-15 18:47:38.952: w/system.err(2220): java.io.ioexception: read failed: ebadf (bad file number) 07-15 18:47:38.962: w/system.err(2220): @ libcore.io.iobridge.read(iobridge.java:432) 07-15 18:47:38.962: w/system.err(2220): @ java.io.fileinputstream.read(fileinputstream.java:179) 07-15 18:47:38.962: w/system.err(2220): @ java.io.inputstream.read(inputstream.java:163) 07-15 18:47:38.962: w/system.err(2220): @ com.example.fileionottext.mainactivity.pdfinandout(mainactivity.java:95) 07-15 18:47:38.962: w/system.err(2220): @ com.example.fileionottext.mainactivity$1.onclick(mainactivity.java:47) 07-15 18:47:38.962: w/system.err(2220): @ android.view.view.performclick(view.java:3531) 07-15 18:47:38.962: w/system.err(2220): @ android.view.view$performclick.run(view.java:14224) 07-15 18:47:38.962: w/system.err(2220): @ android.os.handler.handlecallback(handler.java:605) 07-15 18:47:38.962: w/system.err(2220): @ android.os.handler.dispatchmessage(handler.java:92) 07-15 18:47:38.962: w/system.err(2220): @ android.os.looper.loop(looper.java:137) 07-15 18:47:38.962: w/system.err(2220): @ android.app.activitythread.main(activitythread.java:4699) 07-15 18:47:38.962: w/system.err(2220): @ java.lang.reflect.method.invokenative(native method) 07-15 18:47:38.962: w/system.err(2220): @ java.lang.reflect.method.invoke(method.java:511) 07-15 18:47:38.962: w/system.err(2220): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:790)
the rest of code
public void pdfinandout() throws filenotfoundexception, ioexception { try { fileoutputstream fos = null; file file2; file2 = new file("/mnt/sdcard/replacementpdf.pdf"); // string filename = "testerpdfcopy.pdf"; try { if (!file2.exists()) { file2.createnewfile(); } fos = new fileoutputstream(file2); } catch (exception e1) { // todo auto-generated catch block e1.printstacktrace(); } fileinputstream fis = null; byte[] buffer = new byte[888192]; file filein; filein = new file("/mnt/sdcard/temppdf.pdf"); fis = new fileinputstream(filein); int input = 0; while ((input = fis.read(buffer)) != -1) { // <<-- stack trace error fos.write(buffer, 0, input); log.i("<<<<<>>>>", "fos2 is; " + buffer[7]); try { fos.flush(); fos.close(); fis.close(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } } textviewone.settext(string.valueof(input)); } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); } } }
while ((input = fis.read(buffer)) != -1) { // <<-- stack trace error fos.write(buffer, 0, input);
either must }
, right? or fis.close
executed, , error occur.
log.i("<<<<<>>>>", "fos2 is; " + buffer[7]); try { fos.flush(); fos.close(); fis.close(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); }
Comments
Post a Comment