Can you find out the baby's father before the baby is born?

There's a test where they go in with a needle and get DNA from the baby in the womb but it's highly risky and not something they do. Just wait until he's born.