Bankruptcy will temporarily "stay," or delay foreclosure, but it will only be temporary unless you pay the mortgage (or work out some new payment arrangement with the lender, which is voluntary for them--i.e. they do not have to agree to whatever you propose). The lender can take the property if the loan is not paid; the bankruptcy delays that, while the process works through, but does not prevent it. It will be prevent the lender from forcing you to personally pay the loan or suing you for the debt; all they can do is take the property itself, if you file for bankruptcy.