Close ().
Int
Read()
.
-
-1
Int
Read(byte [] buffer,
count
Int
offset, int count)
buffer, buffer[offset ],
Int
Read(char[] buffer,
count
Int
offset, int count)
buffer, buffer[offset ],
-
, BinaryReader BinaryWriter -. .
// , .
Using System; using System.10;
class RWData {
static void Main() {
BinaryWriter dataOut;
BinaryReader dataln;
int i = 10;
double d = 1023.56;
bool b = true;
string str = " ";
// , try {
dataOut = new
'BinaryWriter(new FileStream("testdata", FileMode.Create));
}
catch(IOException exc) {
Console.WriteLine(" :\" + exc.Message); return;
}
// , try {
Console.WriteLine(" " + i); dataOut.Write(i);
Console.WriteLine(" " + d); dataOut.Write(d);
Console.WriteLine(" " + b); dataOut.Write(b);
Console.WriteLine(" " + 12.2 * 7.4); dataOut.Write(12.2 * 7.4);
Console.WriteLine(" " + str); dataOut.Write(str);
}
catch(IOException exc) {
Console.WriteLine(" -:\n" + exc.Message);
} finally {
DataOut.Close();
}
Console.WriteLine();
// , try {
dataln = new
BinaryReader(new FileStream("testdata", FileMode.Open));
}
catch(IOException exc) {
Console.WriteLine(" :\" + exc.Message) return;
}
try {
i = dataln.Readlnt32();
Console.WriteLine(" " + i); d = dataln.ReadDouble();
Console.WriteLine(" " + d); b = dataln.ReadBoolean();
Console.WriteLine(" " + b); d = dataln.ReadDouble();
Console.WriteLine(" " + d); str = dataln.ReadString();
Console.WriteLine(" " + str);
}
catch(IOException exc) {
Console.WriteLine(" -:\n" + exc.Message);
} finally {
Dataln.Close ();
}
}
}
.
|
|
10 1023.56 True 90.28
10 1023.56 True 90.28
testdata, , , , .
, , -. , , , , . , .
/* BinaryReader BinaryWriter
. */
Using System; using System.10;
class Inventory {
static void Main() {
BinaryWriter dataOut;
BinaryReader dataln;
string item; //
int onhand; //
double cost; //
try {
dataOut = new
BinaryWriter(new FileStream("inventory.dat", FileMode.Create));
}
catch(IOException exc) {
Console.WriteLine("He " +
" ");
Console.WriteLine(": " + exc.Message); return;
}
// , try {
dataOut.Write(""); dataOut.Write(10); dataOut.Write(3.95);
dataOut.Write(""); dataOut.Write(18); dataOut.Write(1.50);
dataOut.Write(""); dataOut.Write(5);
DataOut.Write (4.95);
dataOut.Write(""); dataOut.Write (8); dataOut.Write(8.95);
}
catch(IOException exc) {
Console.WriteLine(" ");
Console.WriteLine(": " + exc.Message);
} finally {
DataOut.Close();
}
Console.WriteLine();
// , try {
dataln = new
BinaryReader(new FileStream("inventory.dat", FileMode.Open));
}
catch(IOException exc) {
Console.WriteLine("He " +
" ");
Console.WriteLine(": " + exc.Message); return;
}
// , .
Console.Write(" : "); string what = Console.ReadLine();
Console.WriteLine();
try {
for (;;) {
// , item = dataln.ReadString(); onhand = dataln.Readlnt32(); cost = dataln.ReadDouble();
// , .
// , .
if(item.Equals(what, StringComparison.OrdinallgnoreCase)) {
Console.WriteLine(item + ": " + onhand + " . " +
": {0:} ", cost);
Console.WriteLine(" <{0}>: {1:}.", item, cost * onhand);
Break;
}
}
}
catch(EndOfStreamException) {
Console.WriteLine(" .");
catch(IOException exc) {
|
|
Console.WriteLine(" ");
Console.WriteLine(": " + exc.Message);
} finally {
Dataln.Close();
} '
}
}