Writing into file -nemerle

60 views
Skip to first unread message

David Ben-Michael

unread,
Mar 27, 2019, 3:36:40 AM3/27/19
to Nemerle Forum

I want to read text from a file, line by line, and for each line - write it at new file.

:I use the following instruction System.IO.File.AppendAllText(@"C:\Users\David Ben Michael\source\repos\nemerle\files\output.asm",line);


.The problem with this code it that the text attched to the file at  a one long line:

: I wish to separate the lines. So Instead of using the instruction above,I used the following code: 


if (fileExt == ".vm" )
{
def sr = System.IO.StreamReader(fi.FullName);
def sw =System.IO.StreamWriter(@"C:\Users\David Ben Michael\source\repos\nemerle\files\output.asm");
mutable line = sr.ReadLine ();


while (line != null) {
sw.WriteLine(line);
//System.IO.File.AppendAllText(@"C:\Users\David Ben Michael\source\repos\nemerle\files\output.asm",line);

line = sr.ReadLine ();



At this case, the compiler create empty file(!). Why the file is empty? and how I resolved this problem?

Thanks


catbert

unread,
Mar 28, 2019, 5:22:12 AM3/28/19
to Nemerle Forum
Hi David!

1) The easiest way to do what you want is
System.IO.File.AppendAllText(@"C:\Users\David Ben Michael\source\repos\nemerle\files\output.asm",line + System.Environment.NewLine); // notice the NewLine stuff

2) I don't see any calls to Flush(), Close() or Dispose() in your second sample. This might be one of the reasons it does not work.

Hope that helps and good luck with learning Nemerle.

Regards,
  -- Ivan.

середа, 27 березня 2019 р. 08:36:40 UTC+1 користувач David Ben-Michael написав:

David Ben-Michael

unread,
May 30, 2019, 10:44:02 AM5/30/19
to Nemerle Forum
Thank You!

בתאריך יום חמישי, 28 במרץ 2019 בשעה 11:22:12 UTC+2, מאת catbert:
Reply all
Reply to author
Forward
0 new messages