aspose file tools
The moose likes Java in General and the fly likes jav filewriter appending to text file at pos x Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "jav filewriter appending to text file at pos x" Watch "jav filewriter appending to text file at pos x" New topic
Author

jav filewriter appending to text file at pos x

Paul Sheehan
Greenhorn

Joined: Aug 05, 2004
Posts: 3
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

Joined: Aug 02, 2004
Posts: 823
I'm not sure that I really understand your post, but have you considered RandomAccessFile?

Jules
Paul Sheehan
Greenhorn

Joined: Aug 05, 2004
Posts: 3
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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: jav filewriter appending to text file at pos x
 
Similar Threads
HELP!!! Output stream closing prematurely
Line Feed Carriage Return problem
problem in appending contents of file.
How to create a file in specified directory
Opening files in append mode