Converting mechanical energy into electricity could have applications in sensing, medical science, defence technology and personal electronics, and the ability of nanowires to 'scavenge' energy from ambient and environmental sources could prove useful for powering nanodevices. Previously reported nanowire generators were based on vertically aligned piezoelectric nanowires that were attached to a substrate at one end and free to move at the other. However, there were problems with the output stability, mechanical robustness, lifetime and environmental adaptability of such devices. Here we report a flexible power generator that is based on cyclic stretching-releasing of a piezoelectric fine wire that is firmly attached to metal electrodes at both ends, is packaged on a flexible substrate, and does not involve sliding contacts. Repeatedly stretching and releasing a single wire with a strain of 0.05-0.1% creates an oscillating output voltage of up to ∼50 mV, and the energy conversion efficiency of the wire can be as high as 6.8%.