Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steklopod/d1849afb99226707e228bf0bb2d43ff1 to your computer and use it in GitHub Desktop.
Save steklopod/d1849afb99226707e228bf0bb2d43ff1 to your computer and use it in GitHub Desktop.
С курсором
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
/*
Запись в существующий файл
*/
public class Solution {
public static void main(String... args) throws IOException {
String fileName = args[0];
long position = Integer.parseInt(args[1]);
String text = args[2];
RandomAccessFile file = new RandomAccessFile(fileName, "rw");
position = position > file.length() ? file.length() : position;
file.seek(position);
file.write(text.getBytes());
file.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment