Suppose i have a text file named Sample.text. i need advice on how to achieve this:
Sample.txt before running a program: ABCD
while running the program, user will input string to be added starting at the middle for example: user input is XXX
Sample.txt after running a program: ABXXXCD
Basically you've got to rewrite the file, at least from the middle. This isn't a matter of Java - it's a matter of what file systems support.
Typically the way to do this is to open both the input file and an output file, then:
See more on this question at Stackoverflow