It means to 'put on a brave face' or pretend to be confident. Whistling is generally a sign of brightness/cheerfulness, whereas darkness is often seen as frightening. Accordingly, if you 'whistle in the dark' you are just covering up the truth that you are really quite scared. Strangely enough, it is quite a recent phrase, dating back no further than the 1930s.