Can you just take a tent, take some food and stay for a few days in national park in Sri Lanka? First of all is it legal to do so? For example are campfires allowed? And if it is legal is it safe? Are there any dangerous animals?
There are quite a few safari camping trips, or organised trekking tours - and they mention for example, that "Wilderness camping sites may include pitching tent in a cave or under a rock face, by the lakeside or high on the plateau. ".
They also suggest "the indigenous Vadda people are always helpful to campers with the Vadda village being an interesting area to camp".
So that would seem to imply that it's acceptable and that the locals are ok with you doing it. However, this could still be because the company has a permit or something that they don't mention.
Sri Lanka Eco Tourism mentions that they have "Camping rules to ensure safe and comfortable camping and Wildlife and/or Forest Department regulations, when applicable".
So it would seem that it's best to identify which national park you want to camp in (Yala, Bundala, etc) and then contact the Forest Department for that park, to find out exactly what is required.
As for the dangerous animals - yes, in parts. In Yala National Park, for example, there are crocodiles hidden everywhere, dangerous lizards, and heaps of other troublesome critters.
It seems the answer would be yes.
Wikitravel's entry on Yala National Park mentions that a day entry pass fee costs LKR 3500, which probably includes camping. I don't find an official government website listing rules, but there are many tour operator pages which mention camping. Yala Hotels (at Yala National Park) says their tour package includes (my emphasis):
This suggests that camping is allowed. What you need to check - and I don't know whether this is your intention - is whether camping is allowed for non-organised parties. I would reckon the answer to be no; with illegal poaching in the Indian subcontinent, forest departments usually tend to keep human activity restricted. Indigenous people could be allowed to live there but there may be restrictions on travellers.