When I connect my Android 4 phone (Galaxy Nexus) to a computer using USB, the storage of the phone is automatically mounted on the computer. How can I connect my phone using USB for charging only? In Android 2.x I had to explicitely choose "USB storage", in Android 4 there is only the choice between MTP and PTP? ):
When your phone is plugged into a computer there should be a USB symbol in the notifications bar. Tapping the notification associated with this should allow you to switch between MTP/PTP (whichever you have selected in settings) and "just charge".
EDIT: apologies, it looks as though this is an HTC-specific thing, and not general. I'm new here - should I leave this answer with this edit, or delete the answer?
Strictly speaking as long as you leave the data lines open the behavior depends on the phone and the computer you plug it into. Your best option would be hardware-only to make sure that the computer doesn't get to see any of the data.
A recently funded Kickstarter project named LockedUSB aims to provide exactly that, also in light of potentially malicious "charging stations" in public places. I'm not linking it since that may be considered spam and that's certainly not the intent behind this answer. A web search can lead the way to them.
From their description:
LockedUSB is an small adapter that allows secure charging of your personal devices. It physically disconnects the data lines, while keeping intruders away from your personal information.
With this kind of solution you will also avoid bad surprises when you forget to switch something off in software on the phone and thereby involuntarily expose your device. Aside from that it's a generic solution that will work without software support on either side and gives you the peace of mind you seem to be looking for when charging your device in other peoples' computers.
Disclosure: I am one of the funders of the above mentioned project on Kickstarter.