• Post Reply Bookmark Topic Watch Topic
  • New Topic

jav filewriter appending to text file at pos x  RSS feed

 
Paul Sheehan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello People,

My problem is as follows ... I have used regex
pattern and matcher to loop through a text file
and write to another. When i use matcher.start and matcher.end it returns the matched pattern
but when I try to append the new string at this
position I want it is appended to the end of the
text file only

I need to be able to append at a pos
matcher.end +1(which could be in the
middle of a text file)

Is this possible? - I am using filewriter to achieve this

I am grateful for any help at all - Thanks
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure that I really understand your post, but have you considered RandomAccessFile?

Jules
 
Paul Sheehan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying Jules

I have solved the problem, but just for clarity I will
retry and explain the problem I had

I would search through text file1 , constantly writing
to text file2 until the character
# was found. I then had to append a string (bla) to the end of
the # mark before writing to text file2 - so text file1 would still
have only # in it, where as textfile2 would have #bla in it

My problem was the logic of my loop, using a string instead of manipulating a stringbuffer and writing the stringbuffer to text file 2
This meant that #bla was always being appended to the very end of text
file2 instead of at the position of #

Thanks anyway for replying jules, perhaps the best way to have done this
was using randomAccess but I was in a real rush to get this done
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!