What to use instead file...?!

Posted on 2005-04-14
Last Modified: 2010-03-31
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!!! 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!
Question by:Valeri
    LVL 11

    Expert Comment

    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?

    LVL 35

    Accepted Solution

    You can use:

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


        writer.toString() ;

    to get the resultant as a String...
    LVL 16

    Author Comment

    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!
    LVL 6

    Expert Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Hire Top Freelancers to Complete Java Projects

    Source the talented Expert Exchange community
    for top quality work on your Java projects.

    Hire the best. Collaborate easily. Get quality work.

    Suggested Solutions

    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now