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

x
  • 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!
0
Valeri
Asked:
Valeri
1 Solution
 
cjjcliffordCommented:
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?

0
 
TimYatesCommented:
You can use:

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

then:

    writer.toString() ;

to get the resultant as a String...
0
 
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!
0
 
cjardCommented:
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
0

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