File input/output: Difference between revisions

Line 1,705:
 
=={{header|M2000 Interpreter}}==
===Using Document Object===
We can use Open for input/ Input$()/close, Open for Output/Print/close, but using a Document object is better, because Load.Doc can find the type of line breack and the coding, if it is UTF-8, UTG-16LE/BE and Ansi (we can provide another argument with specific way to open, or a Locale id for Ansi). When we save the document, we use the same format, so we preserve the coding and the line break type.
 
Line 1,727 ⟶ 1,728:
}
FileInputOutput
</lang>
===Using Buffer Object===
A buffer expose real pointer (address), so here M(0) is the address of first byte, and Len(m) is the size of buffer in bytes. This buffer is not for code, but for data (no execution allowed).
 
<lang M2000 Interpreter>
Module Using_Buffer {
M=buffer("Input.txt")
Print Len(m)
Open "Output1.txt" For Wide Output as #F
Print #F, Eval$(M);
Close #F
Edit "Output1.txt"
z=Filelen("Output1.txt")
Print z
Open "OutputAscii.txt" For Output as #F
Print #F, Eval$(M);
Close #F
Print Filelen("OutputAscii.txt")=z/2
Edit "OutputAscii.txt"
}
Using_Buffer
</lang>
 
Anonymous user