my dog learned polymorphism
The moose likes Java in General and the fly likes Writing to a temporary file in Memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Writing to a temporary file in Memory" Watch "Writing to a temporary file in Memory" New topic

Writing to a temporary file in Memory

Sumon Mukherjee

Joined: Dec 19, 2007
Posts: 12


I have this method that accepts an empty Jdom document as an input argument. There is also a String variable which contains the XML stuff which I need to add to the Jdom document. For eg:
public static Document loadXML(Document jDoc, String strTags)
String will contain-
strTags = "<RequestBody><first>Sumon</first><last>M</last></RequestBody>";
I add this string to my Jdom document and my method returns the modified jdom document which can later be used for other functions.

The problem is i already have the content in my string variable and dont want to create a file in the phsical memory.

One way i can think of is to create a temporary file to wrap this string and delete it on exiting. But this approach has it own problems, say if there are 100's of users logged in and my temporary file has exclusive lock on it.....the waiting time will be too much n my users will prefer not to use my site!

Is there any other way i can wrap this string/convert to File object so that i can ue the temporary Jdom document from the memory.

Any help in this regard will be highly appreciated!

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

I don't see why you need to create a File. I couldn't quite understand what you were trying to pass that String into, but if you want JDOM to parse the XML it contains, surely JDOM can parse from sources other than Files? (I don't have its API documentation on hand but I'm expecting you do.) For example can it parse from a Reader? Like a StringReader?
I agree. Here's the link:
subject: Writing to a temporary file in Memory
It's not a secret anymore!