public class Solution {
public static void main(String... args) throws IOException {
int number=0;
String filename="C:/Users/zubar/OneDrive/Рабочий стол/111.txt";
String text="Hello world";
RandomAccessFile raf = new RandomAccessFile("filename", "rw");
raf.seek(number);
raf.writeBytes(text);
raf.close();
package com.javarush.task.task32.task3201;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
/*
Запись в существующий файл
*/
public class Solution {
public static void main(String... args) {
int number=1;
String filename="C:/Users/zubar/OneDrive/Рабочий стол/111.txt";
String text="Hello world";
try (RandomAccessFile raf = new RandomAccessFile("filename", "rw")) {
raf.seek(number);
raf.writeBytes(text);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}