Julia - write at the beginning of the file

I tried to develop an algorithm that at some point would have to write the results either to the beginning of the file, or to the end.

I am trying to create a sorting algorithm that will not use as much RAM as my files to be sorted are too large for my current specifications. So for the cost of the extra time, I would like to do this directly to the file instead in RAM.

I know that you can write files in Julia this way>

write(outfile,"A, B, C, D\n")

But I cannot find how to write at the beginning of this.

Thanks for the help.

+4
source share
3 answers
s=open("test.txt", "a+");
write(s,"B");
write(s,"C");
position(s) # => 2
seekstart(s);
position(s) # => 0
write(s,"A"); # be careful you are overwriting B!
position(s) # => 1
close(s);
s=open("test.txt", "r");
read(s,Char) # => 'A'
read(s,Char) # => 'C' # we lost 'B'!

, ! - , .

cdata=readall(s);
seekstart(s);
write(s,prependdata);
write(s,cdata);
+5

, deque :

  • , : .

  • , : , .

  • (, , ), .

+4

.

" ".

, .

, , . RAM, .

0
source

Source: https://habr.com/ru/post/1628240/


All Articles