Joseph B. James, 36, of Central Avenue, Batavia, is charged with two counts of criminal sale of a controlled substance, 3rd, and two counts of criminal possession of a controlled substance, 3rd.
James is accused of selling crack cocaine to an agent of the Local Drug Task Force on two occasions last month.
Task Force members arrested James at the County Courts Facility while he was being sentenced in an unrelated case.
He was jailed without bail.
His arrest comes following an investigation into the sale, transportation and possession of crack cocaine in the City of Batavia.
The District Attorney's Office assisted in the investigation.