Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8349035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:52:16+00:00 2026-06-09T07:52:16+00:00

I am trying to read xml file from remote location in my DAO. <bean

  • 0

I am trying to read xml file from remote location in my DAO.

<bean id="queryDAO"
      class="com.contextweb.openapi.commons.dao.reporting.impl.QueryDAOImpl">
  <property name="dataSource" ref="myDS"/>
  <property name="inputSource" ref="xmlInputSource"/>
</bean>

<bean id="fileInputStream" class="java.io.FileInputStream">
  <constructor-arg index="0" type="java.lang.String"
                   value="${queriesFileLocation}"/>
</bean>
<bean id="xmlInputSource" class="org.xml.sax.InputSource">
  <constructor-arg index="0" >
    <ref bean="fileInputStream"/>
  </constructor-arg>
</bean>

I am able to read XML for first time. For subsequent requests, inputstream is exhausted.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T07:52:18+00:00Added an answer on June 9, 2026 at 7:52 am

    You are using FileInputStream thats where the problem lies. Once you have read the data in the stream there is no way you can read the contents again. The stream has reached its end.

    Solution to this problem would be to use another class BufferedInputStream which supports resetting of stream pointing to anywhere in the file.

    Following example shows that BufferedInputStream opened only once and can be used to read the file multiple times.

    BufferedInputStream bis = new BufferedInputStream (new FileInputStream("test.txt"));
    
            int content;
            int i = 0;
    
            while (i < 5) {
    
                //Mark so that you could reset the stream to be beginning of file again when  you want to read it.
                bis.mark(0);
    
                while((content = bis.read()) != -1){
    
                    //read the file contents.
                    System.out.print((char) content);
                }
                    System.out.println("Resetting ");
                    bis.reset();
                    i++;
    
            }
    
        }
    

    There is catch. Since you are not using this class yourself but dependent on org.xml.sax.InputSource to do it, you need to create your own InputSource by extending this class and override getCharacterStream() and getByteStream() methods to mark() reset() the stream to start of the file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read the following xml file from spotify: http://ws.spotify.com/search/1/track?q=sail+awolnation I want to
I have one .net windows application I'm trying to read .xml file from c#
I have an xml file(from federal government's data.gov) which I'm trying to read with
I'm trying to read data from an xml file and display it in a
I'm trying to read the data from an XML file, validating it against the
I have an XML file that I'm trying to read from here , and
I'm trying to read in some sample data from an XML file in a
I'm trying to read xml file from vbs script. Xml is encoded in utf-8
I'm currently trying to READ XML file from the client machine where the user
I am currently trying to read from an xml file which records the jobs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.