A federal judge in Massachusetts on Thursday dismissed a defamation lawsuit against Bill Cosby by an actress - who is the former lover of Sammy Davis Jr. - who claimed that Cosby raped her.

The judge ruled that the comedian acted within his rights when he proclaimed himself innocent of the crime.

U.S. District Judge Mark Mastroianni wrote on Thursday that accuser Katherine Mae McKee had not demonstrated that Cosby defamed her simply by denying her claims, made in an interview with the New York Daily News.

A federal judge has dismissed a defamation lawsuit against Bill Cosby (pictured left in December) by Katherine Mae McKee, an actress who claimed he raped her (right in her younger years)

'An accused person cannot be foreclosed ... from considering the issuance of a simple and unequivocal denial - free from overall defamatory triggers or contextual themes,' Mastroianni wrote.

In 2014, McKee alleged that Cosby forced himself on her after inviting her to a party on a boat in Detroit. As a radiant young actress, she appeared on Sanford and Son and even a 1971 episode of The Cosby Show.

'It was a rape, but it seemed so strange to call it that. We think of rape as a stranger who attacks you in a parking lot,' McKee told the New York Daily News in 2014.

The former Las Vegas showgirl was a party staple among Sammy Davis Jr.'s Rat Pack and said the crooner was in an open marriage, with her as his 'road wife'.

While on the road herself in the early 70s, McKee stuck around Detroit to visit family following a performance. Cosby, she told NYDN, also happened to be in town at the time.

McKee alleged in 2014 that Cosby forced himself on her after inviting her to a party on a boat in Detroit. She is pictured with Sammy Davis Jr, and has said she was his 'road wife'

On Thursday, Cosby tweeted a photograph showing an order of dismissal

McKee told the newspaper that Cosby invited her to the party, and asked that she get some ribs from a local barbecue joint and come pick him up at his hotel.

'I remember I walked in the door, and he had a robe and cap on. He took the ribs from my hands and just grabbed me,' she recalled.

She told the newspaper: 'It was so fast and so shocking and so unbelievable.'

McKee said the rest of the night that Cosby was 'rude and cold' to her.

She told the New York Daily News: 'I never said a word. I was too uncomfortable about it. Bill was so rude and cold toward me the rest of the night.

'I thought, "When this boat docks, I'm out of here." I just left.'

McKee never told her famous lover what happened.

Following the publication of McKee's claims in the newspaper, Cosby penned a letter to the New York Daily News denying the sexual assault allegation, and his attorney requested that the article be retracted, CNN reported.

McKee and Sammy Davis Jr. are pictured together in an undated photograph

McKee's lawsuit had been filed in federal court in Massachusetts, according to The Wrap.

The suit claimed the alleged incident happened in 1974, and he 'immediately set upon and physically attacked her'.

The alleged assault was described as 'shocking, scary and horrible'.

The civil lawsuit is one of a slew of cases brought against the actor, best known for playing the father in the 1980s television hit The Cosby Show, by about 50 women who say he sexually assaulted them, often after plying them with drugs and alcohol, in a series of alleged attacks dating back decades.

The vast bulk of the claims are too old to be the subject of a criminal prosecution, though Cosby is also awaiting trial in Pennsylvania on charges he sexually assaulted a former basketball coach at his alma mater, Temple University.

Cosby has denied wrongdoing in all the cases.

Cosby built a long career on a family-friendly style of comedy before being hit by the wave of allegations.

McKee is 'very disgusted' with the ruling, she told CNN.

The civil lawsuit is one of a slew of cases brought against the actor, best known for playing the father in the 1980s television hit The Cosby Show, by about 50 women who say he sexually assaulted them, often after plying them with drugs and alcohol

Cosby is awaiting trial in Pennsylvania on charges he sexually assaulted Andrea Costand (pictured), a former basketball coach at his alma mater, Temple University

McKee (pictured) is 'very disgusted' with the ruling, she told CNN

On Thursday, Cosby tweeted a photograph showing an order of dismissal.

Attorneys for the 79-year-old entertainer welcomed the decision and compared it to a Pennsylvania court's dismissal of a similar civil case last month.

'This is the correct outcome,' said attorney Angela Agrusa. 'This order, taken in conjunction with the recent decision in the Hill case, amount to a powerful statement of the law.'

However, in his decision, Mastroianni noted there were differences between the case he was dismissing and a separate lawsuit before him brought by accuser Tamara Green and since joined by six other women.

'There is a subtle, yet fundamental, difference between stating or implying that an accuser's allegations are completely fabricated (and failing to fully disclose the non-defamatory facts underlying this assertion), as in Green, and disputing an accuser's credibility based on fully disclosed non-defamatory facts, as here,' Mastroianni wrote.

An attorney for Green said the decision had no bearing on the other Massachusetts case.

'Judge Mastroianni's opinion makes it explicitly clear that he is not backing away from his previous decision in the Green case,' attorney Joseph Cammarata said. 'My clients look forward to their day in court.'