[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

What to use instead file...?!

Hi all,

I'm using TransformerHandler to transform .txt to xml file. This TransformerHandler needs StreamResult to output the tags  created. Ok, it is not so important!
I need structure, such like File, but I don't want to create a file to the disk!!!
java.io.File doesn't create file to the disk, but when I call new FileOutputStream(myFile) it creates the file to the disk! StreamResult needs OutputStream, that way I'm invoke it!
So I need the structure like File, with InputStream and OutputStream, but I dont want to create file to the disk.

Please help!
Thanks in advance!
1 Solution
you could use ByteArrayInputStream/ByteArrayOutputStream...

But if you are converting a .txt file to a .xml file, what's wrong with using FileOutputStream? Or do you want to convert the .txt file into an XML stream?

You can use:

    StringWriter writer = new StringWriter() ;
    StreamResult result = new StreamResult( writer ) ;


    writer.toString() ;

to get the resultant as a String...
ValeriAuthor Commented:
to cjjclifford : Yes, I want to convert .txt file /actually it comes as stream/ to XML stream! Actually I have to work only with streams and I don't want to deal with any files at all.

to TimYates : I'll try this!
it's simple.. youre using a FileOutputStream to write the file to disk.. but you dont want to write it to disk

first you have to decide where you want to write it to, then you write it to that output stream. find a suitable outputstream for what you need, and use it.

example, if you wanted to write to the console, System.out is the OutputStream (it's a PrintStream) you would use
if you wanted to write it to a socket then youy would make the socket, then write it to the OutputStream you get from calling mySocket.getOutputStream()

basically, we cant tell you where to write it to, because you havent told us where you want it written to

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now