I've been a foreigner as myself...actually many times.
I personally think it is inevitable. As stardice mentioned right above me:P, it is usually nothing personal. [Hopefully?]
To actually move into a new world where you are completely new to everything, it could be very scary and nervous. At the worst, one could feel everyone is against him/her. It could be very stressful, really. Unlike the good ol' times [<--how old is this guy?!] people are not so nice unfortunately...[I mean not always, but..] There are always those individuals who want to exploit these helpless foreigners for their own good. [Especially when a foreigner cannot speak the language of the foreign country.]
I'm sure most of foreigners are acting the way they are just to fit into the new world. In their point of view, they could be very stressed since they have to change the way they speak, eat, wear, shop, play, and etc.
If you ever feel bad because of the treatments you've received from them, just try to understand them a little and talk to them. Who knows, this could be your chance to meet a new friend ;)