(Money Magazine) -- Want to invest in a green industry that employs the latest technology, reduces U.S. oil consumption and is priced very attractively? Look no further than the railroads. Laggards for decades after the 19th-century boom ended, they're hot again.

"There was steady traffic growth until last year, and the trend looks good once the economy gets back up to speed," says Kenneth Kremar, an economist who follows the railroad industry for consulting firm Global Insight. Perhaps that's why railroad stocks have largely escaped the battering that other sectors have taken so far this year.

Of course, their business could still be hurt temporarily if the economy deteriorates further. But eventually, says Kremar, "we'll see a pickup in demand, especially in the kinds of commodities railroads carry."

Astute investors are climbing aboard. Warren Buffett has been loading up on shares of Burlington Northern Santa Fe and was buying in January at prices only 13% below current levels. (News of his buying boosted the stock.) At last count, he owned more than 18% of the company.

The chief reason that the railroads' long-term prospects look so good today is that they began upgrading their operations soon after the industry was largely deregulated in 1980. "The railroads finally had an incentive, as well as the cash flow, to reinvest," says Robert E. Gallamore, a former Union Pacific executive and former director of the Transportation Center at Northwestern University.

Those investments took a while to pay off. But the ultimate result, says Gallamore, has been a huge increase in productivity. There are seven giant North American freight railroads, which handle 90% of the continent's traffic. The two largest are Burlington Northern and Union Pacific, both of which are in the Sivy 70.

Here are some of the specific trends that have contributed to the industry's success and that are likely to continue to drive growth:

Technology is creating greater cost efficiencies. Railroads have been merging, and these big systems can enjoy enormous cost efficiencies.

"The key is knowing where your cars are at all times," explains Kremar. Sophisticated software calculates the best way to put different cars together into trains. And onboard electronics assess topography, track curvature, train length and weight to calculate the optimum speed for conserving fuel.

Overall, the Federal Railroad Administration calculates that productivity has more than doubled since 1990.

Globalization and growth are providing a lot of new business. Railroad capacity can be increased only slowly, while demand has been rising quickly. That gives the industry some ability to raise rates.

In addition to domestic growth, booming imports from Asia and from NAFTA partners Canada and Mexico are contributing, and so is foreign demand for U.S. coal and grain.

The ethanol industry has also created a new source of business. "Both the corn used to make ethanol and the finished product are most likely to be shipped by rail," says Kremar.

Railroads are far more energy-efficient than their competition. Locomotives today get 80% more mileage from a gallon of diesel than they did in 1980. As a result, trains consume far less fuel than trucks do to move the same amount of freight.

That not only saves on costs, it reduces emissions of greenhouse gases. In fact, the Environmental Protection Agency calculates that for distances of more than 1,000 miles, using trains rather than trucks alone reduces fuel consumption and greenhouse gas emissions by 65%.

A second-half rebound

Railroads have seen a drop-off in shipments connected with home building and construction during the past few months, but most other business lines are solid.

And earnings held up fairly well last year. Union Pacific (UNP, Fortune 500) reported a small earnings increase for the fourth quarter and a 17% rise for 2007 as a whole. Some of that profit gain was attributable to stock repurchases.

UP expects some softness in the first half of 2008, with a pickup in business in the second half. For the year as a whole, earnings are expected to top $8 a share, a gain of more than 15% compared with last year. Based on those estimates, the shares are currently selling at a 15.1 price/earnings ratio.

Burlington Northern's (BNI, Fortune 500) results have been less robust recently. Although the company has bought back more than 14 million shares, both fourth-quarter and full-year earnings were just about flat.

Burlington has been cautious in its predictions for 2008, but earnings are projected to grow more than 14% annually over the next five years. The shares trade at just under a 15 P/E.

Burlington has a record of more consistent management than Union Pacific does. As a result, some analysts think Burlington has the better long-term prospects - an assessment with which Buffett seems to agree.