As others point out, the bugs get in your stored food because the eggs or larvae are already in the food when you store it.
After a few pantry weevil investations we have resorted to the freeze treatment.
In fact, we bought an inexpensive older, used freezer primarily for this purpose.
Other than canned foods, foods that just can’t be frozen or foods we will eat almost immediately, we now pass every food product through the freezer. That includes grains, rice, pasta, flour, cake mixes, prepared dressings, dry soups, yeast, seasonings, etc.
When the food comes in, it goes in the freezer and stays there until we need the room for the next batch. But we make sure foods stay in for sufficient time - usually at least a week. Some foods we are using, like an open bag of flour or rice, are stored there until they are used up.
So far it seems to work.
>>After a few pantry weevil infestations we have resorted to the freeze treatment.
For anyone dealing with an infestation, I can recommend the pheromone traps from Do Your Own Pest Control. They work great.
http://store.doyourownpestcontrol.com/propest-pheronet-trap-pantry-pest