本文整理汇总了C#中System.IO.BinaryReader.Close方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.BinaryReader.Close方法的具体用法?C# System.IO.BinaryReader.Close怎么用?C# System.IO.BinaryReader.Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryReader
的用法示例。
在下文中一共展示了System.IO.BinaryReader.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
public static void Load()
{
IO.Log.Write(" Loading CampaingProgresss...");
levelsCompleted.Clear();
System.IO.BinaryReader br = new System.IO.BinaryReader(new System.IO.FileStream("Saves/progress.lpg",
System.IO.FileMode.Open));
String s = "";
int l = 0;
while (br.PeekChar() > -1)
{
s = br.ReadString();
l = br.ReadInt32();
byte[] d = new byte[l];
for (int j = 0; j < l; j++)
{
d[j] = br.ReadByte();
}
levelsCompleted.Add(s, d);
}
br.Close();
IO.Log.Write(" Loading complete");
}
示例2: GetDllMachineType
public static MachineType GetDllMachineType(this string dllPath)
{
// See http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx
// Offset to PE header is always at 0x3C.
// The PE header starts with "PE\0\0" = 0x50 0x45 0x00 0x00,
// followed by a 2-byte machine type field (see the document above for the enum).
//
using (var fs = new System.IO.FileStream(dllPath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
using (var br = new System.IO.BinaryReader(fs)) {
MachineType machineType = MachineType.IMAGE_FILE_MACHINE_UNKNOWN;
// bool isgood = false;
try {
fs.Seek(0x3c, System.IO.SeekOrigin.Begin);
Int32 peOffset = br.ReadInt32();
fs.Seek(peOffset, System.IO.SeekOrigin.Begin);
UInt32 peHead = br.ReadUInt32();
if (peHead != 0x00004550)
// "PE\0\0", little-endian
throw new Exception("Can't find PE header");
machineType = (MachineType)br.ReadUInt16();
// isgood = true;
}
catch {
// isgood = false;
}
finally {
br.Close();
fs.Close();
}
return machineType;
}
}
示例3: Read
public override byte[] Read(long ID)
{
System.IO.FileStream fs = null;
System.IO.BinaryReader r = null;
try {
string path = BuildFilePath(ID);
if (!System.IO.File.Exists(path))
return null;
fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
r = new System.IO.BinaryReader(fs);
int len = (int)fs.Length;
byte [] b = r.ReadBytes(len);
return b;
}
finally {
if (r != null)
r.Close();
if (fs != null)
fs.Close();
}
}
示例4: LoadData
/// <summary>
/// ファイルからデータをロード
/// </summary>
public static void LoadData()
{
if(System.IO.File.Exists(@SAVEFILE)){
using(var fs = System.IO.File.Open(@SAVEFILE,System.IO.FileMode.Open)){
// バイナリリーダ作成
var br = new System.IO.BinaryReader(fs);
// Read data
Global.isStageOpened[(int)StageID.Stage1] = br.ReadBoolean();
Global.isStageOpened[(int)StageID.Stage2] = br.ReadBoolean();
Global.isStageOpened[(int)StageID.Stage3] = br.ReadBoolean();
Global.characterLevel = br.ReadInt32();
Global.characterExp = br.ReadInt32();
br.Close();
}
}else{
Global.isStageOpened[(int)StageID.Stage1] = true;
Global.isStageOpened[(int)StageID.Stage2] = false;
Global.isStageOpened[(int)StageID.Stage3] = false;
Global.characterLevel = 1;
Global.characterExp = 0;
}
}
示例5: FileToByteArray
public byte[] FileToByteArray(string _FileName)
{
byte[] _Buffer = null;
try
{
// Open file for reading
System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
// attach filestream to binary reader
System.IO.BinaryReader _BinaryReader = new System.IO.BinaryReader(_FileStream);
// get total byte length of the file
long _TotalBytes = new System.IO.FileInfo(_FileName).Length;
// read entire file into buffer
_Buffer = _BinaryReader.ReadBytes((Int32)(_TotalBytes));
// close file reader
_FileStream.Close();
_FileStream.Dispose();
_BinaryReader.Close();
}
catch (Exception _Exception)
{
// Error
Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
}
return _Buffer;
}
示例6: FileToArray
public static byte[] FileToArray(string sFilePath)
{
System.IO.FileStream fs = new System.IO.FileStream(sFilePath,
System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
br.Close();
fs.Close();
return bytes;
}
示例7: GetTGASize
public static System.Drawing.Size GetTGASize(string filename)
{
System.IO.FileStream f = System.IO.File.OpenRead(filename);
System.IO.BinaryReader br = new System.IO.BinaryReader(f);
tgaHeader header = new tgaHeader();
header.Read(br);
br.Close();
return new System.Drawing.Size(header.ImageSpec.Width, header.ImageSpec.Height);
}
示例8: Show_Info
public System.Windows.Forms.Control Show_Info(sFile file)
{
System.IO.BinaryReader br = new System.IO.BinaryReader(System.IO.File.OpenRead(file.path));
string ext = new String(br.ReadChars(4));
br.Close();
if (ext == "NFTR" || ext == "RTFN")
{
return new FontControl(pluginHost, NFTR.Read(file, pluginHost.Get_Language()));
}
return new System.Windows.Forms.Control();
}
示例9: GetImage
public byte[] GetImage(string filepath)
{
filepath = System.Web.Hosting.HostingEnvironment.MapPath(filepath);
//string FolderPath = Server.MapPath("Images");
System.IO.FileStream fs = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
byte[] image = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
return image;
}
示例10: FileToByteArray
public static byte[] FileToByteArray(string _FileName)
{
byte[] _Buffer = null;
try
{
// Open file for reading
System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.BinaryReader _BinaryReader = new System.IO.BinaryReader(_FileStream);
long _TotalBytes = new System.IO.FileInfo(_FileName).Length;
_Buffer = _BinaryReader.ReadBytes((Int32)_TotalBytes);
_FileStream.Close();
_FileStream.Dispose();
_BinaryReader.Close();
}
catch
{
//
}
return _Buffer;
}
示例11: Show_Info
public Control Show_Info(sFile file)
{
System.IO.BinaryReader br = new System.IO.BinaryReader(System.IO.File.OpenRead(file.path));
string ext = "";
try { ext = new String(br.ReadChars(4)); }
catch { }
br.Close();
if (file.name.ToUpper().EndsWith(".TGA"))
return new TGA(pluginHost, file.path).Show_Info();
else if (file.name.ToUpper().EndsWith(".JPG"))
return new JPG(pluginHost, file.path).Show_Info();
else if (file.name.ToUpper().EndsWith(".PNG"))
return new PNG(pluginHost, file.path).Show_Info();
else if (file.name.ToUpper().EndsWith(".WAV") || ext == "RIFF")
return new WAV(pluginHost, file.path).Show_Info();
else if (file.name.ToUpper().EndsWith(".BMP"))
return new BMP(pluginHost, file.path).Show_Info();
return new Control();
}
示例12: Start
public void Start(string InputFilename, string OutputFilename, UInt64 Key, DESMode.DESMode Mode, bool Decode)
{
using (System.IO.BinaryReader Reader = new System.IO.BinaryReader(System.IO.File.Open(InputFilename, System.IO.FileMode.Open)))
{
using (System.IO.BinaryWriter Writer = new System.IO.BinaryWriter(System.IO.File.Open(OutputFilename, System.IO.FileMode.OpenOrCreate)))
{
const int MaxSize = 1048576;
int n = 0;
byte[] buffer = new byte[MaxSize];
int size = 0;
int k = 0;
UInt64 DESResult = 0;
while ((n = Reader.Read(buffer, 0, MaxSize)) > 0)
{
k = 0;
while (n > 0)
{
if ((n / 8) > 0)
size = 8;
else
size = n;
byte[] tempArray = new byte[size];
for (int i = 0; i != size; ++i, ++k)
tempArray[i] = buffer[k];
if (!Decode)
DESResult = Mode.EncodeBlock(GetUIntFromByteArray(tempArray), Key);
else
DESResult = Mode.DecodeBlock(GetUIntFromByteArray(tempArray), Key);
Writer.Write(GetByteArrayFromUInt(DESResult, size), 0, size);
n -= 8;
}
}
Writer.Close();
}
Reader.Close();
}
}
示例13: FileToByteArray
/// <summary>
/// Function to get byte array from a file
/// </summary>
/// <param name="fileName">File name to get byte array</param>
/// <returns>Byte Array</returns>
public static byte[] FileToByteArray(string fileName)
{
byte[] buffer;
// Open file for reading
var fileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
// attach filestream to binary reader
using (var binaryReader = new System.IO.BinaryReader(fileStream))
{
var totalBytes = new System.IO.FileInfo(fileName).Length;
// read entire file into buffer
buffer = binaryReader.ReadBytes((Int32)totalBytes);
// close file reader
fileStream.Close();
fileStream.Dispose();
binaryReader.Close();
}
return buffer;
}
示例14: GetData
public override void GetData()
{
System.IO.FileStream file = new System.IO.FileStream(filename, System.IO.FileMode.Open);
System.IO.BinaryReader reader = new System.IO.BinaryReader(file);
reader.BaseStream.Seek(filePointer, System.IO.SeekOrigin.Begin);
byte[] fileData = reader.ReadBytes(32);
filePointer += 32;
Append(fileData);
reader.Close();
file.Close();
}
示例15: GetFileTrueType
/// <summary>
/// 真正判断文件类型的关键函数(不太准确,比如txt获取到的值都不一样)
/// </summary>
/// <param name="hifile"></param>
/// <returns></returns>
public static string GetFileTrueType(System.Web.HttpPostedFile postedFile)
{
//System.IO.FileStream fs = new System.IO.FileStream(strPhysicsPath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.Stream fs = postedFile.InputStream;
System.IO.BinaryReader r = new System.IO.BinaryReader(fs);
string fileclass = "";
byte buffer;
try
{
buffer = r.ReadByte();
fileclass = buffer.ToString();
buffer = r.ReadByte();
fileclass += buffer.ToString();
}
catch { }
r.Close();
fs.Close();
/*文件扩展名说明
*7173 gif
*255216 jpg
*13780 png
*6677 bmp
*239187 txt,aspx,asp,sql
*208207 xls.doc.ppt
*6063 xml
*6033 htm,html
*4742 js
*8075 xlsx,zip,pptx,mmap,zip
*8297 rar
*01 accdb,mdb
*7790 exe,dll
*5666 psd
*255254 rdp
*10056 bt种子
*64101 bat
*/
if (fileclass == "255216")//说明255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar
{
return "jpg";
}
else if (fileclass == "7173")
{
return "gif";
}
else if (fileclass == "6677")
{
return "bmp";
}
else if (fileclass == "13780")
{
return "png";
}
else if (fileclass == "7790")
{
return "exe";
}
else if (fileclass == "8297")
{
return "rar/zip";
}
else if (fileclass == "208207")
{
return "doc/xls";
}
else if (fileclass == "8075")
{
return "docx/xlsx";
}
else if (fileclass == "5155")
{
return "txt";
}
else if (fileclass == "6787")
{
return "swf";
}
else
{
return "";
}
}