http://wiki.developerforce.com/page/Chatter_Code_Recipes
//Adding a Text post
FeedItem post = new FeedItem();
post.ParentId = oId; //eg. Opportunity id, custom object id..
post.Body = ‘Enter post text here’;
insert post;
//Adding a Link post
FeedItem post = new FeedItem();
post.ParentId = oId; //eg. Opportunity id, custom object id..
post.Body = ‘Enter post text here’;
post.LinkUrl = ‘http://www.someurl.com’;
insert post;
//Adding a Content post
FeedItem post = new FeedItem();
post.ParentId = oId; //eg. Opportunity id, custom object id..
post.Body = ‘Enter post text here’;
post.ContentData = base64EncodedFileData;
post.ContentFileName = ‘sample.pdf’;
insert post;