Looks like you forgot an else statement and I modified your intent a little:
if (!file.exists()) {
Toast.makeText(MyActivity.this, " the file not found",Toast.LENGTH_LONG).show();
}
else {
Intent intent = new Intent(MyActivity.this,BooksActivity.class );
startActivity(intent);
}
3
solved How to run my Intent if file exists [closed]