Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to see an IO file

Posted on 2004-09-17
19
Medium Priority
?
224 Views
Last Modified: 2010-03-31
Hi,

I am retreiving data from oracle from my java application in an xml format and then im writing it to a file using buffered writer, I would like to show this output file, how can i show this file to users?

import java.sql.*;
import java.math.*;
import oracle.xml.sql.query.*;
import oracle.jdbc.*;
import oracle.jdbc.driver.*;
import java.io.*;


public class xmlretTest {
   
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       
    String tableName = "emp1";
    Connection conn;
   
    try
    {
     DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
                     
     conn = DriverManager.getConnection ("");
                       
     OracleXMLQuery qry = new OracleXMLQuery(conn, "select * from emp1");
     
     String sx = qry.getXMLString();
     
     
                     try
   
                     {
                         
                     File temp = File.createTempFile("pattern", ".suffix");
                     BufferedWriter out = new BufferedWriter(new FileWriter(temp));

                     out.write(sx);
                     out.toString();
                     //System.out.println(sx);
                     }
                     
                     catch (IOException e) {
                                        System.out.println(e);
                                  }
    }
   
  catch (SQLException e)
              {
                 e.printStackTrace();      
              
                     System.out.println(e);
                                          
              }
}
}
0
Comment
Question by:vihar123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 5
  • +1
19 Comments
 

Expert Comment

by:Emilda
ID: 12082313
As sx is in String format you can print it out using System.out.println(sx).
0
 

Author Comment

by:vihar123
ID: 12082388
I want to show it as some txt file
0
 

Author Comment

by:vihar123
ID: 12082434
Is my question not clear????
why am i not getting any replies?
please its urgent, all contributions will be appreciatted
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Expert Comment

by:Emilda
ID: 12082464
Yes, question is not clear. What do you mean by showing it as a text file.
0
 

Author Comment

by:vihar123
ID: 12082492
to show the retreived data in a .txt file, for eg:- taking all the data into display.txt and showing it to the users
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12082501
Well create that text file ......

;JOOP!
0
 

Expert Comment

by:Emilda
ID: 12082516
In the code you have shown you are already writing it into a file. Do you want to pop up application like notepad and show the contents of display.txt in it.

Is that what you want.

You can pop-up notepad by using

Runtime r = Runtime.getRuntime();
r.exec(path_to_noteopad);
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12082543
If not, add:

        temp.close();
        temp.renameTo("display.txt");
just after:
                     out.toString();
                     //System.out.println(sx);
;JOOP!
0
 

Author Comment

by:vihar123
ID: 12082566
>>> Do you want to pop up application like notepad and show the contents of display.txt in it.

ya i want this, can u send me in detail, im unable to understand where to write what :-)
0
 

Expert Comment

by:Emilda
ID: 12082585
You can include these lines below the statement to close the file.

temp.write(..)
temp.close();

Runtime r = Runtime.getRuntime();
r.exec(path_to_noteopad);

But this can only pop-up Notepad and user needs to later open up the text file from the saved location.
0
 
LVL 37

Accepted Solution

by:
zzynx earned 2000 total points
ID: 12082589
Try

public class xmlretTest {
   
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       
    String tableName = "emp1";
    Connection conn;
   
    try
    {
     DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
                     
     conn = DriverManager.getConnection ("");
                       
     OracleXMLQuery qry = new OracleXMLQuery(conn, "select * from emp1");
     
     String sx = qry.getXMLString();
     
     
                     try
   
                     {
                         
                     File temp = File.createTempFile("pattern", ".suffix");
                     BufferedWriter out = new BufferedWriter(new FileWriter(temp));

                     out.write(sx);
                     out.close();

                     temp.renameTo("display.txt");
                     Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + temp.getAbsolutePath());
                   
                     }
                     
                     catch (IOException e) {
                                        System.out.println(e);
                             }
    }
   
  catch (SQLException e)
             {
                e.printStackTrace();      
             
                    System.out.println(e);
                                     
             }
}
}
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12082610
Explanation:

>> temp.renameTo("display.txt");
This renames the file to a *.txt file

>> Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + temp.getAbsolutePath());
This starts up the program related to a *.txt file (notepad or whatever other program)

0
 

Expert Comment

by:Emilda
ID: 12082612
That's cool.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12082621
Thanks, zzynx.
;JOOP!
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12082631
:°)

Let's hope vihar feels like that too ;°)
0
 

Author Comment

by:vihar123
ID: 12082639
thanks zzynx its working, can u also tell me how to send this file to a database. thanks :-)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12082669
>> thanks zzynx its working
Good! Question closed then.

>>Can u also tell me how to send this file to a database
Yes. But that's another question.
0
 

Author Comment

by:vihar123
ID: 12082691
>>>>Yes. But that's another question.

hey thats cool answer :-)), ok ill put it as a new question.

thanks
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12082724
Thanks

>> hey thats cool answer
;°)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

636 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