Dogs bite for differenent reasons. Some bite as a form of playing. They don't know they are doing anything wrong unless they have been properly trained to avoid biting humans. Some bite out of fear. They think they are going to be hurt or threaten in some manner so they strike first so to speak. Some bite as a result of being startled. For example if someone were to step on a dog's tail or pull their fur too hard, a dog might react with a bite to let the person know "Hey, you hurt me". And the worst type of dogs who bite are the ones who bite out of agression. They feel they have to be dominant or protectiive over something or someone and bite to show where they stand. Try to look at the 2 times you were bit and see if you can tell which circumstance it was and then it might help you respond if you are in a similar situation. For example, if the dog bit of fear, the next time you are around a shy or fearful dog, try to give it its space and let it come to trust that you are not going to make any sudden moves etc. If you feel that either of the bites were due to aggression, I would avoid being around those dogs unless the owners have taken action/trainging to avoid a similar situation in the future. Unfortunately, not all dogs who bite can be trained to not bite, no matter why they bite. Years ago I had a Char Pei that had possibly been mistreated. We don't know his full back ground. He came to trust us and was even great with our DD who was around 2 at the time, although I never put her in a situation where I was fully trusting the dog around her. But he could never be trusted with strangers because every now and then he would act agressive out of fear. After 1 bite and several close calls we had to have him put down. That was one of the hardest things I have ever had to do, but we couldn't take the risk of someone getting seriously hurt.
Most dogs are good dogs and I hope these 2 situations has not caused you to mistrust dogs in general. Each one has its own little quirks and I hope your situations were just flukes.