Write to line in file
Is there some method of script to write to a specific line in a file?
I tried some things like
but writeLine is not a method...
public String writeFile(int x, String info) throws IOException
BufferedWriter writer = new BufferedWriter(new FileWriter("test.txt"));
int startLine = x;
int endLine = x;
for (int i = 0; i < startLine; i++)
info = writer.writeLine();
for (int i = startLine; i < endLine + 1; i++)
So I was wondering if there were any methods to solve this.
Did you read the Java doc about readLine() ? How can you say that it's not a method, depends on what you say that?
No, read the original file, line for line, and write each of those lines to a new temp file. When you get the line that needs to be changed, deleted, inserted, whatever, do that and write it out to the new temp file, then continue reading the original and writing it to the new. Close both streams, delete the original file and rename the new temp file.
Can you not write a writer class and have a method that returns the information and prints it out.