• Post Reply Bookmark Topic Watch Topic
  • New Topic

Overwriting text file in java  RSS feed

 
karthik munukuntla
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all, i am trying to Display Contents of two files in an html table. but the second file is overwriting the first file. give me suggestions please.



 
Liutauras Vilda
Sheriff
Posts: 4927
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
karthik munukuntla,

I have corrected code tags you were trying to use as well as code formatting.
Please remind yourself how to UseCodeTags (<- link) correctly.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also don't use // comments for anything long. Use/* comments */

You have not shown how you are writing with those two streams, so we cannot see where the problem is.
 
karthik munukuntla
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello campbell. heres the code

 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And where are you writing anything in that code?
Don't expect people to read such a long block of code. You have to show us where you think the problem is.
 
Paul Clapham
Sheriff
Posts: 22836
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Here the value of names.length is 2, so you're running the loop body twice, once for each of the streams.

So for the first time through you create an A2Parser object and fill it with information from the first stream. For the second time through you create another A2Parser object, discarding the first A2Parser, and fill it with information from the second stream. It may look like the second time through is "overwriting" the data in an A2Parser object, but in fact it's just creating a new A2Parser object.

I'm not sure what you expected, or even what you want. Did you expect (or want) a single A2Parser object combining the information from the two files, or what?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!