.


:




:

































 

 

 

 


Using System; using System.10;. static void Main() { string str;




class KtoD {

static void Main() { string str;

FileStream fout;

// -, try {

fout = new FileStream("test.txt", FileMode.Create);

catch(IOException exc) {

Console.WriteLine(" :\" + exc.Message); return;

}

// - StreamWriter. StreamWriter fstr_out = new StreamWriter(fout);

try {

Console.WriteLine(" , ''."); do {

Console.Write (": "); str = Console.ReadLine();

if(str!= "") {

str = str + "\r\n"; // fstr_out.Write(str);

}

} while(str!= "");

} catch(IOException exc) {

Console.WriteLine(" -:\n" + exc.Message);

} finally {

Fstr_out.Close();

}

}

}

StreamWriter. :

StreamWriter(string )

StreamWriter(string , bool append)

, . append true, . . , . - IOException. , .

, , StreamWriter.

// StreamWriter.

Using System; using System.10;

class KtoD {

static void Main() { string str;

StreamWriter fstr_out = null; try {

// , StreamWriter.

fstr_out = new StreamWriter("test.txt");

Console.WriteLine(" , ''."); do {

-Console.Write (": "); str = Console.ReadLine ();

if(str!= "") {

str = str + "\r\n"; // fstr_out.Write(str);

}

} while(str!= "");

} catch(IOException exc) {

Console.WriteLine(" -:\n" + exc.Message);

} finally {

if(fstr_out!= null) fstr_out.Close();

}

}

}

StreamReader

StreamReader. StreamReader . :

StreamReader(Stream )

. ArgumentNullException, , ArgumentException, . StreamReader . StreamReader . .

test. txt. .

// ,

// StreamReader.

Using System; using System.10;

class DtoS {

static void Main() {

FileStream fin; string s;

try {

fin = new FileStream("test.txt", FileMode.Open);

catch(IOException exc) {

Console.WriteLine(" :\" + exc.Message); return;

}

StreamReader fstr_in = new StreamReader(fin); try {

while((s = fstr_in.ReadLine())!= null) {

Console.WriteLine(s);

}

} catch(IOException exc) {

Console.WriteLine(" -:\n" + exc.Message);

} finally {

Fstr_in.Close();

}

}

}

, . ReadLine () , , . , StreamReader EndOfStream. true, , false. , EndOf Stream . while .

while(!fstr_in.EndOfStream) { s = fstr_in.ReadLine();

Console.WriteLine(s);

}

EndOf Stream, . EndOf Stream , .

, StreamReader, StreamWriter. :

StreamReader(string )

, . . FileNotFoundException. , ArgumentNullException. , ArgumentException. , IOException DirectoryNotFoundException.

, , Console. In, . . , , . , .

. , < >, Console. In Console. Out . , .

Using System;

class Test {

static void Main() {

Console.WriteLine(" .");

}

}

Test > log

" ." log. . , "".

< >, , #, . -, , , Windows, , . , . Setln (), SetOut () SetError (), Console.

static void Setln(TextReader __) static void SetOut(TextWriter __)

static void SetError(TextWriter ____)

, Setln () . , , TextReader. SetOut () , TextReader. , FileStream, StreamWriter. .

// Console.Out.





:


: 2016-12-03; !; : 474 |


:

:

.
==> ...

1582 - | 1444 -


© 2015-2024 lektsii.org - -

: 0.013 .