The subway is safe. If you're staying in Flushing, you'd take the Airtrain to Jamaica and get the subway. Take the Manhattan-bound E train to Jackson Heights and transfer for the Flushing-bound 7 train. Be aware that routes change late nights, so check the www.mta.info web site for updates. You can also ride the E train to Court Square and get the 7 there. You could also just take a yellow taxi. Be sure to go to the official taxi line, do not take a ride with the touts who approach you at the airport.
I don't know why you're even thinking about staying in Flushing though. Are you trying to just "kill time?" If that's the case, just book a hotel by the airport so you can get some rest. But if you want to see New York, stay in Manhattan. Think about it this way -- if you stay at an airport hotel, it'll take you 15-20 minutes to get to your terminal. If you stay in Manhattan and use the subway to get back to JFK, it takes about an hour. So, you're saving about 45 minutes if you stay at the airport.....not worth it in my opinion. Make the most of your short layover instead, and see something of the city.