This week's book giveaways are in the iOS and Features new in Java 8 forums.
We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line!
See this thread and this one for details.
The moose likes I/O and Streams and the fly likes I/O of XML file within memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "I/O of XML file within memory" Watch "I/O of XML file within memory" New topic

I/O of XML file within memory

Sanjit Singh

Joined: Nov 12, 2001
Posts: 27
Hi everyone,
This is fairly a basic question and I am somehow confused how to implement it due to my lack of experience with Java I/O.
I have an XML document that I am gerneating on the fly and writing it out to a file with PrintWriter out statements on a FileOutputStream.
I want to achieve the following:
I want another class (exists within the same JVM) to get hold of this XML document without reading it out of the file. In other words, I want everything to remain in memory, so that no file system is involved.
Is it possible to write the contents of the XML document out on the stream into the memory and have my other java program simply read it in through an input stream (without any sockets).
I am not sure whether this is possible, so any help would be appreciated. Even some sample code would be nice. THANKS!
Rodney Woodruff
Ranch Hand

Joined: Dec 04, 2001
Posts: 80
As you write your xml document out you could store the contents in a String object. You could either pass or provide access to this String object to your other class and then you would have what you were looking for.
However, have you considered using JAXP to both create and read your xml document. This would make a little easier to manage access to your xml document without opening streams.

Hope This Helps
I agree. Here's the link:
subject: I/O of XML file within memory