java - Android Studio - FileNotFound exception in editor -
i'm getting error in android studio ide before hitting "run".
unhandled exception: java.io.filenotfoundexception
with class:
(the function in class not yet being called!)
import java.io.*; public class fileio { public static byte[] readbinaryfilefromassets(file file) { byte[] data = null; datainputstream dis = new datainputstream(new fileinputstream(file)); dis.readfully(data); dis.close(); return data; } } thanks.
its bothering because haven't handled potential file not found exception. surround try/catch or throw exception.
public static byte[] readbinaryfilefromassets(file file) { byte[] data = null; datainputstream dis = null; try { dis = new datainputstream(new fileinputstream(file)); dis.readfully(data); dis.close(); } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } return data; } note: can automatically surround blocks in try/catch in android studio doing alt+enter bring options , selecting "surround try/catch"
Comments
Post a Comment