digitalmars.D - writing files: trouble
- Miguel Ferreira Simões (24/24) May 31 2004 I need some help...
- Miguel Ferreira Simões (3/3) May 31 2004 I noticed that FileMode.Out overrides the file it it exists previously.....
- Ben Hinkle (3/4) May 31 2004 stream.write(char[]) will first write the length of the string and then ...
-
Kris
(7/11)
May 31 2004
- Miguel Ferreira Simões (7/11) May 31 2004 Thanks. One problem solved...
- Ben Hinkle (4/8) May 31 2004 I think you have to use std.file:
- Vathix (3/11) May 31 2004 File has a create method.
- Dennis Walters, II (6/10) Jun 01 2004 What version of dmd or gdc are you using for this? Using dmd 0.90
- Miguel Ferreira Simões (9/13) Jun 02 2004 I am using dmd 0.91. (windows xp sp1)
I need some help... I am trying to save a file. It (almost works)... but it happens that this code prints some extra characters in the beggining of the file. why? void save(char[] filename){ int node, offset; OutBuffer buffer = new OutBuffer(); buffer.reserve(20*_xdim*_ydim); buffer.printf("lines = %d\r\n", _ydim); buffer.printf("columns = %d\r\n", _xdim); for (int line = 0; line < _ydim; ++line){ for (int col = 0; col < _xdim; ++col){ offset = node*_nways; buffer.printf("node %d = %d:%d:%d:%d:%d\r\n", node, _paths[offset + 0], _paths[offset + 1], _paths[offset + 2], _paths[offset + 3], _bonus[node++]); } } buffer.printf("\r\n"); File file = new File(filename, FileMode.Out); file.write(buffer.toString()); file.close(); thanks, Miguel
May 31 2004
I noticed that FileMode.Out overrides the file it it exists previously... the result is a file that is a mix of two files!?! (running windows xp sp1/dmd 0.91)
May 31 2004
file.write(buffer.toString());stream.write(char[]) will first write the length of the string and then the string contents. The function writeString will just write the contents: file.writeString(buffer.toString());
May 31 2004
<shameless plug> this is where multiple distinct readers/writers (BinaryWriter, DisplayWriter etc)really helps within mango.io :-) </shameless plug> "Ben Hinkle" <bhinkle4 juno.com> wrote in message news:c9go14$28s4$1 digitaldaemon.com...thefile.write(buffer.toString());stream.write(char[]) will first write the length of the string and thenstring contents. The function writeString will just write the contents: file.writeString(buffer.toString());
May 31 2004
Thanks. One problem solved... what can I do to have the writeString() function not overriding an existing file, I mean delete the file and then write, just like an fopen(filename, "w"); "Ben Hinkle" <bhinkle4 juno.com> escreveu na mensagem news:c9go14$28s4$1 digitaldaemon.com...thefile.write(buffer.toString());stream.write(char[]) will first write the length of the string and thenstring contents. The function writeString will just write the contents: file.writeString(buffer.toString());
May 31 2004
Miguel Ferreira Simes wrote:Thanks. One problem solved... what can I do to have the writeString() function not overriding an existing file, I mean delete the file and then write, just like an fopen(filename, "w");I think you have to use std.file: if (std.file.exist(filename)) std.file.remove(filename); and catch any exceptions that may be thrown if something fails.
May 31 2004
"Ben Hinkle" <bhinkle4 juno.com> wrote in message news:c9gs25$2ei4$1 digitaldaemon.com...Miguel Ferreira Simes wrote:File has a create method.Thanks. One problem solved... what can I do to have the writeString() function not overriding an existing file, I mean delete the file and then write, just like an fopen(filename, "w");I think you have to use std.file: if (std.file.exist(filename)) std.file.remove(filename); and catch any exceptions that may be thrown if something fails.
May 31 2004
On Tue, 1 Jun 2004 03:47:27 +0100 "Miguel Ferreira Sim=F5es" <kobold netcabo.pt> wrote:Thanks. One problem solved... what can I do to have the writeString() function not overriding an existing file, I mean delete the file and then write, just like an fopen(filename, "w");What version of dmd or gdc are you using for this? Using dmd 0.90 and/or the current gdc, my files are overwritten (completely recreated) when using File(someString, FileMode.Out) to construct the File stream. Dennis
Jun 01 2004
I am using dmd 0.91. (windows xp sp1) "Dennis Walters, II" <scruff myrealbox.com> escreveu na mensagem news:20040601232230.6a15982c.scruff myrealbox.com... On Tue, 1 Jun 2004 03:47:27 +0100 "Miguel Ferreira Simões" <kobold netcabo.pt> wrote:Thanks. One problem solved... what can I do to have the writeString() function not overriding an existing file, I mean delete the file and then write, just like an fopen(filename, "w");What version of dmd or gdc are you using for this? Using dmd 0.90 and/or the current gdc, my files are overwritten (completely recreated) when using File(someString, FileMode.Out) to construct the File stream. Dennis
Jun 02 2004