Hi I want to display the contents of a xml file.

Hi i dont't know how to read a xml file using DOM parser in java.Can anybody help me out in this the following is the xml file
[=========================================
<MODULE ID="RWORLD" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:/C:/Projects/RWORLD/RDP_rate.xsd">
<PHONE_TYPE>RIM
<RWORLD_PLAN>L0
<RATE>3
</RATE>
</RWORLD_PLAN>
<RWORLD_PLAN>L1
<RATE>0
</RATE>
</RWORLD_PLAN>
<RWORLD_PLAN>L2
<RATE>0
</RATE>
</RWORLD_PLAN>
</PHONE_TYPE>
<PHONE_TYPE>FWP
<RWORLD_PLAN>L0
<RATE>3
</RATE>
</RWORLD_PLAN>
<RWORLD_PLAN>L1
<RATE>0
</RATE>
</RWORLD_PLAN>
<RWORLD_PLAN>L2
<RATE>0
</RATE>
</RWORLD_PLAN>
</PHONE_TYPE>
<PHONE_TYPE>PCO
<RWORLD_PLAN>L0
<RATE>3
</RATE>
</RWORLD_PLAN>
<RWORLD_PLAN>L1
<RATE>0
</RATE>
</RWORLD_PLAN>
<RWORLD_PLAN>L2
<RATE>0
</RATE>
</RWORLD_PLAN>
</PHONE_TYPE>
<PHONE_TYPE>FWT
<RWORLD_PLAN>L0
<RATE>3
</RATE>
</RWORLD_PLAN>
<RWORLD_PLAN>L1
<RATE>0
</RATE>
</RWORLD_PLAN>
<RWORLD_PLAN>L2
<RATE>0
</RATE>
</RWORLD_PLAN>
</PHONE_TYPE>
</MODULE>
===================
I want to read the above file and the output should be in the following format :
======
Phone_Type , RWorld_Type , Rate
RIM L0 3
RIM L1 0
RIM L2 0
FWP L0 3
FWP L1 0
FWP L2 0
PCO L0 3
PCO L1 0
PCO L2 0
FWT L0 3
FWT L1 0
FWT L2 0
======

Use an XSLT for the specified format.

Similar Messages

  • Want to display the contents of a text file in a jsp

    hi
    i am new to jsp, i want to display the contents of a text file in a jsp file ,whenever jsp file is loaded from browser.
    -thanx

    i had come up with the code
    <!-- form.jsp -->
    <%@ page import="java.io.*, java.lang.*" %>
    <%@ page language="java" %>
    <html>
    <head>
    <title>Display</title>
    </head>
    <body>
    <%
    String sample[100];
    String line;
    %>
    <%! int i=0; %>
    <%!File f1 = new File("c:\\file.txt"); %>
    <% try { %>
    <%!FileReader fi = new FileReader(f1); %>
    <% } catch(FileNotFoundException io) { } %>
    <%!BufferedReader in = new BufferedReader(fi); %>
    <%
    while((line=in.readLine())!= null)
    sample= line;
    i++;
    in.close();
    %>
    i will display sample here
    </body>
    </html>
    but i am getting error
    display_jsp.java:16: unreported exception java.io.FileNotFoundException;
    must be caught or declared to be thrown
    FileReader fi = new FileReader(f1);
    ^
    plz help
    -thanx

  • Unable to display the Content of a data file from within another data file in Oracle webcenter portal.

    We have a Content Presenter taskflow. This task flow is added to a jspx page. The taskflow fetches the content from the contributor data file. The contributor data file is having a WYSIWYG editor. The content of the WYSIWYG editor is being displayed correctly through the task flow.
    We have some links in the WYSIWYG editor. These links again point to some data files. When we click on these links from within the portal, then we are getting a blank page(the url of this blank page is: http://localhost:7101/eWSIBPortal/faces/oracle/webcenter/sitestructure/render.jspx?datasource=UCM%23dDocName%3AWSIB_ARTICLE) and not displaying the content of the data file that we are pointing to from the WYSIWYG editor.
    We want to display the content of these data files(which we have pointed from WYSIWYG editor) in-line within the portal.
    Please help us to resolve this issue and let us know if any information is required from our end.

    Thanks for reply. However, can I use XSQL to dump the formated text to a file? or just can display to client through web browsers?

  • Can we Read/Display the content of Word/PDF file  in Flex 3/4 ?

    Hello All,
    Can we  read/display the content of Word/PDF file in Flex 3 or Flex 4?.  I have one word file containing  Arabic  and English content with some settings like  Bold, Color, Align etc. I want to display the content of this word file as it is in the flex web application.
    Awaiting for prompt reply.
    Thanks and Regards

    thank you for your immediate reply, but,
    sorry, this does not work.
    With this code:
    <cfpdf action = "read" source = "dok_1.pdf" name =
    "mypdf">
    <cfdump var="#mypdf#"/>
    I get this result:
    Everything, but no text of the document.
    PDFDocument
    Application name of application
    Author bimbam Verlag GmbH
    CenterWindowOnScreen [empty string]
    ChangingDocument Allowed
    Commenting Allowed
    ContentExtraction Allowed
    CopyContent Allowed
    Created D:20080710
    DocumentAssembly Allowed
    Encryption No Security
    FilePath [empty string]
    FillingForm Allowed
    FitToWindow [empty string]
    HideMenubar [empty string]
    HideToolbar [empty string]
    HideWindowUI [empty string]
    Keywords [empty string]
    Language [empty string]
    Modified [empty string]
    PageLayout SinglePage
    Printing Allowed
    Producer [empty string]
    Properties [empty string]
    Secure Allowed
    ShowDocumentsOption [empty string]
    ShowWindowsOption [empty string]
    Signing Allowed
    Subject [empty string]
    Title Rheinische Angler-Zeitschrift
    TotalPages 1
    Trapped [empty string]
    Version 1.3
    Maybe i do not understand the cfpdf tag the right way.
    What i want is a kind of pdf-to-text conversion.
    Do I have to use the processddx action? I do not think so.
    But there is a property DocumentText .. ?

  • Display the content of a text file in a browser

    I am new to servlet, I have written a java servlet code which can read a file and display its content in command prompt only(resin),i would like to ask how can i display the content on the browser and i also want to ask how to write a servlet which can display the conetent from a web browser( e.g. whatever i type in a form) and produce the result in the text file.
    import java.io.FileReader;
    import java.io.IOException;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class read extends HttpServlet
    public void doGet (HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException
    String applicationPath =
         getServletContext().getRealPath ("");
    String filePath =
         getServletContext().getRealPath ("/WEB-INF/text.txt");
    FileReader fr = new FileReader (filePath);
    for (int chr = fr.read(); chr != -1; chr = fr.read())
    System.out.print ((char) chr);
    }

    You have to create an object of PrintWriter and use that to display the output on the browser.
    PrintWriter out = response.getWriter();
    out.println(chr);
    Hope this helps..
    Arun

  • Help on how to read the content of an XML file from the payload

    I have a receiver channel / mail adapter, that sends e-mails with a XML attachment.
    I’m trying to write a Bean, that should make it possible to rename the attached XML file dynamically.
    In the Bean I want to read the content of the attached XML file, it could be the “order number”.
    The filename should then be “Order number”.XML.
    <u><i>Can anyone help me with how to read the content of the XML file from the payload.</i></u>
    <i><b>Frank</b></i>

    hi,
    check this: http://jakarta.apache.org/poi/

  • I want to read the content of a text file dropped in a watched folder into a string variable

    I have a workbench process with 2 variable.
    inDoc (DataType=Document/input/required)
    outStr (DataType = String/output)
    The document being passed to the workflow is a text file with 4 lines of text in it.  when the text file is dropped into the watched folder, it will be assigned to the inDoc parameter in the workflow.
    My workflow needs to extract the 4 lines of text and write it into a string (outStr).
    Id like to use the FileUtilsService.ReadString service but i can't since its input parameter is the file path.  When i do, i get the following error...
    Caused by: ALC-FUT-001-011: File rO0ABXNyABZjb20uYWRvYmUuaWRwLkRvY3VtZW50yAEFUxsO+CEDACNJAAtfY2FsbGJhY2tJZFoADV9kZXNlcmlhb Gl6ZWRJABBfZGlzcG9zYWxUaW1lb3V0WgAJX2Rpc3Bvc2VkWgAZX2lzRGlzcG9zYWxUaW1lb3V0RGVmYXVsdFoAE19 pc1RyYW5zYWN0aW9uQm91bmRKAAdfbGVuZ3RoSQAOX21heElubGluZVNpemVaAAhfb3duRmlsZVoAC19wYXNzaXZhd GVkWgALX3BlcnNpc3RlbnRJABFfc2VuZGVyQ2FsbGJhY2tJZFoAEV9zZW5kZXJQYXNzaXZhdGVkWgARX3NlbmRlclB lcnNpc3RlbnRJAA5fc2VuZGVyVmVyc2lvbkkABl9zdGF0ZUwAC19hdHRyaWJ1dGVzdAATTGphdmEvdXRpbC9IYXNoT WFwO0wACF9jYWNoZUlkdAAfTGNvbS9hZG9iZS9pZHAvRG9jdW1lbnRDYWNoZUlEO0wADF9jYWxsYmFja1JlZnQAIUx jb20vYWRvYmUvaWRwL0lEb2N1bWVudENhbGxiYWNrO0wADF9jb250ZW50VHlwZXQAEkxqYXZhL2xhbmcvU3RyaW5nO 0wAC19kYXRhQnVmZmVydAAeTGNvbS9hZG9iZS9zZXJ2aWNlL0RhdGFCdWZmZXI7TAAPX2V4cGlyYXRpb25UaW1ldAA QTGphdmEvbGFuZy9Mb25nO0wABV9maWxldAAOTGphdmEvaW8vRmlsZTtMABBfZ2xvYmFsQmFja2VuZElkdAAhTGNvb S9hZG9iZS9pZHAvRG9jdW1lbnRCYWNrZW5kSUQ7WwAHX2lubGluZXQAAltCTAAMX2lucHV0U3RyZWFtdAAVTGphdmE vaW8vSW5wdXRTdHJlYW07TAAPX2xvY2FsQmFja2VuZElkcQB+AAhMAAxfcHVsbFNlcnZhbnR0ACRMY29tL2Fkb2JlL 2lkcC9JRG9jdW1lbnRQdWxsU2VydmFudDtMABFfcmFuZG9tQWNjZXNzRmlsZXQAGkxqYXZhL2lvL1JhbmRvbUFjY2V zc0ZpbGU7TAAVX3NlbmRlckNhbGxiYWNrUmVmSU9ScQB+AARMABZfc2VuZGVyR2xvYmFsQmFja2VuZElkcQB+AAhMA A1fc2VuZGVySG9zdElkcQB+AARMABVfc2VuZGVyTG9jYWxCYWNrZW5kSWRxAH4ACEwAGl9zZW5kZXJQdWxsU2VydmF udEpuZGlOYW1lcQB+AARMAARfdXJsdAAOTGphdmEvbmV0L1VSTDt4cHcGAAAAAwAAcHd1AHMwOjA6MDowOjA6MDowO jEvMTI3LjAuMC4xLy8vLy8vLy8vZmU4MDowOjA6MDo3NDMyOmU0OWQ6NmUzMToxNTU0JTEwLzEwLjI0LjIzOS4xMjY vZmU4MDowOjA6MDowOjVlZmU6YTE4OmVmN2UlMTEvLy8vdXIAAltCrPMX+AYIVOACAAB4cAAAAcRJTU01MjU3XzAxL TIwMTFfMXwwMXx8YXx8fHxGZW1hbGV8MjAwMHw2fDh8Y3wyNTZ8MjU2fDkxMnwwMXx8fHx8fHx8Tnx8fHx8fHx8fHx 8fHx8fHx8fHxZfHx8fHx8fHx8fDAyfHx8fHx8TnwyMDEyfDJ8MTR8DQpJTU01MjU3XzAxLTIwMTFfMnx8fHx8fHx8f Hxhc2RmfDI1NnwyMDEyfDAyfDAxfDIwMTJ8MDN8MDJ8fHx8YXxhfDI1Mnx8fHxZfHx8fHx8fHx8fHx8fHx8DQpJTU0 1MjU3XzAxLTIwMTFfM3xOfHx8fHx8fHx8fDIwMDB8Nnx8fGFzZGZ8YXNkZnxhc2RmfDI1Nnx8fHx8fHx8fHx8fHx8f Hx8fHx8DQpJTU01MjU3XzAxLTIwMTFfNHxOfE58fE58TnxOfHxOfE58fE58TnxOfA0KSU1NNTI1N18wMS0yMDExXzV 8U2luZ2xlfDAxfHwyMDEyfDAyfDE4fDIwMTJ8MDN8MDN8MjM0fGFzZGZ8fGFzZGZhc3x8fHxFeGNoYW5nZS1Qcm8uO S40MDEuRnVsbC5XSU4uZW5fQ0EuRU5VLTEwLTIwMTF8DQoNCnBwdwYAAAAAAAB0AAp0ZXh0L3BsYWlucHNyABFqYXZ hLnV0aWwuSGFzaE1hcAUH2sHDFmDRAwACRgAKbG9hZEZhY3RvckkACXRocmVzaG9sZHhwP0AAAAAAAAx3CAAAABAAA AADdAAKd3NmaWxlbmFtZXQAJ0M6XFVzZXJzXENodWxseS5QYXJrXERlc2t0b3BcaGRzY2FuLnR4dHQACGJhc2VuYW1 ldAAKaGRzY2FuLnR4dHQABGZpbGVxAH4AFXh3NwAtYWRvYmUvaWRwL0RvY3VtZW50UHVsbFNlcnZhbnQvYWRvYmVqY l9MQ19ERVYx//////////94 does not exist.
    at com.adobe.livecycle.fileutils.FileUtilsService.readDocument(FileUtilsService.java:363)
    which is what i expected...
    I've also tried with the Script.executeScript to call some java code but im not too strong in java and in all the examples i find, the file pointer requires a file path.
    import java.io.*;
    FileInputStream f = new FileInputStream(patExecContext.getProcessDataValue("/process_data/inDoc"));
    OR
    File f = new File(patExecContext.getProcessDataValue("/process_data/inDoc"));
    OR
    File f = patExecContext.getProcessDataValue("/process_data/inDoc");
    Any clue how to resolve my problem?

    Try the following code snippet to read the String content from the file recieved through watched folder endpoint.
    com.adobe.idp.Document inputDoc = patExecContext.getProcessDataDocumentValue("/process_data/inDoc");
    java.io.InputStream inStream = inputDoc.getInputStream();
    byte[] dataBuffer = new byte[inStream.available()];
    inStream.read(dataBuffer);
    String strData = new String(dataBuffer);
    patExecContext.setProcessDataStringValue("/process_data/outStr",strData);
    The code is not tested, hence if you find any mistakes, correct and test the functionality.
    Nith

  • Reading an XML file and write the contents to another xml file in java

    Hi,
    I am new to xml parsing.My requirement is that I am getting a message (xml) using ibm MQ in the ByteArrayInputStream format.I have to read this xml message and write to another file.
    I am creating a POC for this.
    First I used simple reading and writing concept but the output is "java.io.FileInputStream@3e25a5 "
    Sample xml file
    - <Client>
    <ClientId>1234</ClientId>
    <ClientName>STechnology</ClientName>
    <DTU_ID>567</DTU_ID>
    <ClientStatus>ACTIVE</ClientStatus>
    - <LEAccount>
    <ClientLE>678989</ClientLE>
    <LEId>56743</LEId>
    - <Account>
    <AccountNumber>9876543678</AccountNumber>
    </Account>
    </LEAccount>
    - <Service>
    <Cindicator>Y2Y</Cindicator>
    <PrefCode>980</PrefCode>
    <BSCode>876</BSCode>
    <MandatoryContent>MSP</MandatoryContent>
    </Service>
    </Client>
    code:
    import java.io.ByteArrayInputStream;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    public class ByteArrayInputStreamToXml {
         public static void main(String srg[]) throws IOException{
              InputStream inputStream= new FileInputStream("C:\\soft\\test2\\sample1.xml");
              byte currentXMLBytes[] = inputStream.toString().getBytes();
              ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(currentXMLBytes);
              OutputStream out = new FileOutputStream("C:\\soft\\test\\data.xml");
              int read=0;
              byte[] bytes = new byte[1024];
              while((read = byteArrayInputStream.read(bytes))!= -1){
              out.write(bytes, 0, read);
              out.write( '\n' );
              inputStream.close();
              out.flush();
              out.close();
              System.out.println("New file created!");
    Please suggest me how can I use DOM/SAX parser ,I can see several code on net for reading xml file using SAX/DOM parser but writing an xml file after reading it using ByteArrayInputStream I am not getting .A help through some example Link will also be helpful for me.
    Thanks
    Sumit
    Edited by: user8687839 on Apr 30, 2012 2:37 AM
    Edited by: user8687839 on Apr 30, 2012 2:43 AM

    Thanks I got the result.
    package com.sumit.collections;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    public class ByteArrayInputStreamToXml {
         public static void main(String srg[]) throws IOException{
              InputStream inputStream= new FileInputStream("C:\\soft\\test2\\sample1.xml");
              ByteArrayOutputStream buffer = new ByteArrayOutputStream();
              int nRead; byte[] data = new byte[1024];
              while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
              buffer.write(data, 0, nRead); } buffer.flush();
              byte currentXMLBytes[]= buffer.toByteArray();
              /* byte currentXMLBytes[] = inputStream.toString().getBytes();*/
              ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(currentXMLBytes);
              OutputStream out = new FileOutputStream("C:\\soft\\test\\data.xml");
              int read=0;
              byte[] bytes = new byte[1024];
              while((read = byteArrayInputStream.read(bytes))!= -1){
              out.write(bytes, 0, read);
              out.write( '\n' );
              inputStream.close();
              out.flush();
              out.close();
              System.out.println("New file created!");
    }

  • Dynamic frame building using the contents of an XML file

    Hello,
    My task is to parse an XML file, which contains various profiles of people. Based on what I read, I will then have to make up the GUI dynamically based on which person is selected. I have decided to use CardLayout and I was wondering if there was any way I could build a dynamic frame in netbeans, using the swing palette that is. Is there anyway I could pass in the frame details (based on a person) and is there a way that Netbeans could build the frame for me?
    Could you guys let me know if this is feasible at all?
    Thanks
    Lexus

    >
    Could you guys let me know if this is feasible at all?>It sure is. The SaverBeans settings dialog does just that, for the XScreenSaver style XML used to configure screensavers. It was developed by Mark Roth using NetBeans.
    Some more information on that component can be found in the [Screensaver configuration files|https://screensavers.dev.java.net/config/] page.
    Edited by: AndrewThompson64 on Dec 27, 2008 12:43 PM

  • How to display the contents of a text file on the command line?

    I realize I need to utilize classes from the java.io.* package, but I don't know which ones to use exactly. This is what I would like to do in a nutshell:
    public static void main(String[] args) throws IOException {
    File inputFile = new File( <path to the file>);
    // code that reads data from the above file and is able to
    // append it to  a string object or display it on the command
    // line (System.out.println)
    }Thanks for your time!

    It's pretty easy. Here's a little example that reads a file, stores it in a string, and prints it to the command line.
    import java.io.*;
    public class OpenFile {
         public static void main(String args[]) {
              try {
                   File fileToOpen = new File("something.txt");
                   FileReader fileIn = new FileReader(fileToOpen);
                   BufferedReader br = new BufferedReader(fileIn);
                   String fileContent = new String();
                   String line;
                   while ((line = br.readLine()) != null) {
                        fileContent += line + "\n";
                   System.out.println(fileContent);
                   br.close();
              catch (IOException e) {
                   System.out.println("Exception: " + e);
    }Good luck,
    Alex

  • Displaying the contents of internal table- in email Step of workflows

    Hello Folks,
    I wanted to display the contents of an internal table ( would contain a list of opportunites ), in an email sent throught the workflow:
    My idea was to LOOP AT <ITAB> into <WA> from an external program and then call the workflow for each content of the <WA>. This will be a problem as, if there are like 1000 records in the internal table, then workflows will be called 1000 times...sending 1000 emails..
    My requirement is that we need to send a single email to the single person, displaying the content of the internal table in the email body......
    My question
    1) Is this scenario possible through worflows ?
    2) If not, please provide an alternative ..
    Thanks
    Anand

    Do you mean to say that just by inserting the multiline element
    within the body of the 'Send email' step type, the contents
    of the multiline element is displayed automatically without
    we having to loop at it somehow ?
    Follow the below apporach,
    1. First create a multiline container element in the workflow conatiner.
    2. Populate the internla table , by using the bor methods and pass back the populated ITAB to the WF by using the binding concept.
    3. Now create a mail step in the workflow, you have the option of inserting the workflow container elements into the mail conten, so insert the multiline container element , then it prompts to select the option like a) Do you liek to display only first line b) Display the ITAB line by line c) Display ITAB lines continuously with out line break.
    4. based upon the requirement select any one of the options.
    Note: Make sure the line length of the ITAB won't excced 132 charecters, because the send mail step will consider only 132 characters.

  • How to display the contents of a document set on a page?

    I want to display the contents of a document set (that contains both folders and files) on a page (with the same structure as they are in the document set like folders and files). How to achieve this?
    I tried content search webpart but it is of no use as it displays the flat list instead I need folders and files as they are present in the document set
    I tried document set contents webpart but as it doesn't accept any connection, it is not of much use.
    I will be glad if you have any pointers for me in this regard.
    Regards
    Kesava

    Hi Kesava,
    According to your description, you might want to display the content in a document set with its hierarchy.
    How about using
    Page Viewer Web Part to display the page of the corresponding document set? This would be a non-code solution I would recommend.
    More information about Page Viewer Web Part:
    https://support.office.com/en-nz/article/Page-Viewer-Web-Part-e364436c-0ec4-4819-acac-1982b3525531
    Thanks
    Patrick Liang
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support,
    contact [email protected]
    Patrick Liang
    TechNet Community Support

  • How to display the content of a file in the portal?

    Hey guys, could anyone help?
    I just created a page which includes two iView, one is KM Navigation iView to display a certain repository, while the other is for displaying the content of a certain file I click in the navigation iView.
    And now the problem is when I click a file in the KM Navigation iView, it will pop up a new window to display it. How can I make it displayed in a fixed iView, which type of this iView should be?

    Hi,
    you can try to use the:
    <b>ConsumerTreeListPreview</b>
    layout for KM navigation ivew (or customize to your own).
    This layout shows a folder tree on the left, a document list on the right. When you click on a document from the list it shows the contents of the file on the bottom of the iview.
    Hope this helps,
    Romano

  • Error in reading the contents of a zip file

    EHello Experts,
    I want to read the contents of a zip file.I have written the following program which reads the contents of a file named "index.xml" which resides in ReadZip.zip.My problem is , it is reading only the first line of that file & after that it is giving this error.
    java.io.IOException: Stream closed
    at java.util.zip.ZipInputStream.ensureOpen(ZipInputStream.java:43)
    at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:67)
    at components.ReadZipFile2.main(ReadZipFile2.java:26)
    public class ReadZipFile2 {
        public static void main(String args[]) {
            try {
                FileInputStream fis = new FileInputStream("C:\\ReadZip.zip");
                ZipInputStream zis = new ZipInputStream(fis);
                ZipEntry ze;
                while ((ze = zis.getNextEntry()) != null) {
                    System.out.println(ze.getName());
                    if (ze.getName().equals("ReadZip/index.xml")) {
                        long size = ze.getSize();
                        if (size > 0) {
                            System.out.println("Length is " + size);
                            BufferedReader br = new BufferedReader(
                                    new InputStreamReader(zis));
                            String line;
                            while ((line = br.readLine()) != null) {
                                System.out.println(line);
                            br.close();
            } catch (IOException e) {
                e.printStackTrace();
    }It seems that zis is getting close after reading the first entry of file.I am unable to guess the reason for this.Please help.Thanx in advance.

    [redacted confused advice]
    [_Compressing and Decompressing Data using Java - with many code samples_|http://java.sun.com/developer/technicalArticles/Programming/compression/|Yes Virginia, there really are code samples]

  • Displaying the contents of an array of objects

    Hello All,
    My Java teacher gave us a challenge and I'm stumped. The teacher wants us to display the contents of the array in the main menthod. The original code is as follows:
    public class TestObjects
         public static void main ( String args[] )
              Thing[] thingArray = { new Thing(4), new Thing(7) };
    }I understand that the elements of the array are objects, and each one has a value assigned to it. The following code was my first attempt at a solution:
    public class TestObjects
         public static void main ( String args[] )
              Thing[] thingArray = { new Thing(4), new Thing(7) };
                                    for ( int i = 0; i < thingArray.length; i++)
                                       System.out.println( thingArray );                         
    }To which I'm given what amounts to garbage output. I learned from reading about that output that its basically displaying the memory location of the array, and the the contents of the array. There was mention of overriding or bypassing a method in System.out.println, but I don't believe that we're that far advanced yet. Any thoughts? I know I have to get at the data fields in the objects of the array, but i'm not having an easy time figuring it out. Thanks very much in advance!

    robrom78 wrote:
    public class TestObjects
         public static void main ( String args[] )
              Thing[] thingArray = { new Thing(4), new Thing(7) };
    for ( int i = 0; i < thingArray.length; i++)
    System.out.println( thingArray );                         
    Note that you're trying to print the entire array at every loop iteration. That's probably not what you meant to do.
    You probably meant to do something more like
                                 System.out.println( thingArray[i] );Also, note that the java.util.Arrays class has a toString method that might be useful.
    To which I'm given what amounts to garbage output. It's not garbage. It's the default output to toString() for arrays, which is in fact the toString() defined for java.lang.Object (and inherited by arrays).
    I learned from reading about that output that its basically displaying the memory location of the array, and the the contents of the array.It displays a default result that is vaguely related to the memory, but probably shouldn't be thought of us such. Think of it as identifying the type of object, and a value that differentiates it from other objects of the same type.
    By the way I assume you mean "+not+ the contents of the array" above. If so, that is correct.
    There was mention of overriding or bypassing a method in System.out.println, but I don't believe that we're that far advanced yet. Any thoughts? No, you don't override a method in println; actually methods don't contain other methods directly. You probably do need to override toString in Thing.
    I know I have to get at the data fields in the objects of the array, but i'm not having an easy time figuring it out. You can get to the individual objects in the array just by dereferencing it, as I showed you above.
    But I suspect that won't be sufficient. Most likely, Thing doesn't have a toString method defined. This means that you'll end up with very similar output, but it will say "Thing" instead of "[Thing" and the numbers to the right of the "@" will be different.
    You'll need to override the toString() method in Thing to get the output you want.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for