Good day. Tried to make a program in which data is added to the beginning of the file. Push me to think, with what classes and methods can this be realized? An example of my implementation (do not scold the bad code, I will be glad to justify comments), in which the existing data is overwritten.
import java.io.*; public class Solution { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); File file = new File(reader.readLine()); RandomAccessFile ramFile = new RandomAccessFile(file, "w"); FileInputStream inputStream = new FileInputStream(reader.readLine()); byte[] b = new byte[2048]; while(inputStream.available() > 0){ int count = inputStream.read(b); ramFile.seek(0); ramFile.write(b, 0, count); } reader.close(); ramFile.close(); inputStream.close(); } }