本文整理汇总了C#中BinaryWriter.Close方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryWriter.Close方法的具体用法?C# BinaryWriter.Close怎么用?C# BinaryWriter.Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryWriter
的用法示例。
在下文中一共展示了BinaryWriter.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: JoinFile
public static void JoinFile(string inputFile, string outputFile, KsSplitJoinHandler handler)
{
long rwIncrament=500000;//updateInterval=400000, updateIndex=0;
FileInfo fInfo=new FileInfo(inputFile);
long iLen=fInfo.Length;
FileStream ifs=new FileStream(inputFile, FileMode.Open);
BinaryReader reader=new BinaryReader(ifs);
//bool cont;
FileInfo fi=new FileInfo(outputFile);
FileMode fm=FileMode.Append;
if(!fi.Exists) fm=FileMode.CreateNew;
FileStream ofs=new FileStream(outputFile, fm);
BinaryWriter writer=new BinaryWriter(ofs);
long i=0, cnt;
while(i<iLen) {
cnt=rwIncrament;
if((i+cnt)>=iLen) cnt=iLen-i;
//byte val[cnt];
writer.Write(reader.ReadBytes((int)cnt));
i+=cnt;
if(!handler.OnUpdate(inputFile, outputFile, i, iLen)) {
ifs.Close(); reader.Close();
ofs.Close(); writer.Close();
handler.OnCanceled(inputFile, outputFile, i, iLen);
return;
}
}
ifs.Close(); reader.Close();
ofs.Close(); writer.Close();
handler.OnFinished(inputFile, outputFile, i, iLen);
}
示例2: SaveItems
public void SaveItems()
{
MemoryStream ms = null;
BinaryWriter writer = null;
// CryptoStream encStream = null;
// FileStream file = null;
try
{
ms = new MemoryStream();
// DESCryptoServiceProvider mDES = new DESCryptoServiceProvider();
// mDES.Mode = CipherMode.ECB;
// mDES.Key = System.Text.Encoding.UTF8.GetBytes(TweaksSystem.CRYPTO_KEY);
//
// CryptoStream encStream = new CryptoStream(ms, mDES.CreateEncryptor(), CryptoStreamMode.Write);
// BinaryWriter writer = new BinaryWriter(encStream);
writer = new BinaryWriter(ms);
if (writer != null) {
writer.Write(UserCloud.USER_DATA_VERSION);
writer.Write(icePicks);
writer.Write(snowballs);
writer.Write(hourglasses);
writer.Write(itemTokens);
writer.Close();
}
// encStream.Close();
ms.Close();
File.WriteAllBytes(saveFile, ms.ToArray());
}
catch (Exception ex)
{
Debug.Log("Error in create or save user file data. Exception: " + ex.Message);
}
finally
{
if (writer != null) {
writer.Close();
}
if (ms != null) {
ms.Close();
}
}
}
示例3: GetMemberOrParent
public void GetMemberOrParent(string id)
{
IList<Hashtable> listMembers = bl.GetmemberInfo(id, 0);
IList<Hashtable> list = null;
string imgs = "";
if (listMembers != null)
{
list = bl.GetmemberInfo(id, 1);
Hashtable htb = new Hashtable();
htb = listMembers[0];
if (htb["B_ATTACHMENT"] != null && htb["B_ATTACHMENT"].ToString() != "")
{
byte[] imgBytes = (byte[])(htb["B_ATTACHMENT"]);
string filePath = "../Files/" + htb["T_USERID"] + ".jpg";
imgs = filePath;
filePath = Server.MapPath(filePath);
BinaryWriter bw = new BinaryWriter(File.Open(filePath, FileMode.OpenOrCreate));
bw.Write(imgBytes);
bw.Close();
}
}
obj = new
{
img = imgs,
list = list,
};
string result = JsonConvert.SerializeObject(obj);
Response.Write(result);
Response.End();
}
示例4: FileStream
IEnumerator ShareScreenshotInterface.ShareScreenshot(byte[] screenshot, bool isProcessing, string shareText, string gameLink, string subject)
{
isProcessing = true;
string destination = Path.Combine(Application.persistentDataPath, "Screenshot.png");
FileStream fs = new FileStream(destination, FileMode.OpenOrCreate);
BinaryWriter ww = new BinaryWriter(fs);
ww.Write(screenshot);
ww.Close();
fs.Close();
AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND"));
AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "file://" + destination);
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), shareText + gameLink);
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_SUBJECT"), subject);
intentObject.Call<AndroidJavaObject>("setType", "image/png");
AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
currentActivity.Call("startActivity", intentObject);
isProcessing = false;
yield return new WaitForSeconds(1);
}
示例5: makeAtlas
public static void makeAtlas(Texture2D[] textures)
{
if (textures != null && textures.Length > 1)
{
// Make our atlas gameobject with a blank atlas script on it.
GameObject go = new GameObject("TEST_ATLAS");
go.AddComponent<Atlas>();
// The blank texture is replaced with the packed texture.
Texture2D tex = new Texture2D(2, 2);
// Now pack the textures
Rect[] UVs = tex.PackTextures(textures, 2, 4096);
// Create out spriteAnimation components onto the atlas with height/width equal to the source.
for (int i = 0; i < UVs.Length; i++)
{
SpriteAnimation anim = go.AddComponent<SpriteAnimation>();
anim.setData(textures[i].name, UVs[i]);
}
FileStream fs = new FileStream(Application.dataPath + "/Resources/Sprites/Atlas_Sprite.png", FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(tex.EncodeToPNG());
bw.Close();
fs.Close();
//PrefabUtility.CreatePrefab(Application.dataPath + "/Resources/Atlases/" + go.name + ".prefab", go);
}
else
{
Debug.LogWarning("Given Textures are null or singular.");
}
}
示例6: RpcTellClientTime
public void RpcTellClientTime(int current_count)
{
current_count = 60 * 5 - current_count;
int min = current_count / 60;
int sec = current_count % 60;
int ten_sec = sec / 10;
int one_sec = sec % 10;
score_.text = "ClearTime:" + min.ToString() + ":" + ten_sec.ToString() + one_sec.ToString();
score_.gameObject.SetActive(true);
hi_score_text_.gameObject.SetActive(true);
if (current_count > hi_score_) return;
if (is_director_) return;
is_director_ = true;
{
var path = Application.dataPath + "/" + "ranki.txt";
FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
BinaryWriter writer = new BinaryWriter(fs);
if (writer != null)
{
writer.Write(current_count);
writer.Close();
}
}
StartCoroutine(ChangeColor());
}
示例7: CreatePhoto
void CreatePhoto()
{
try
{
string strPhoto = Request.Form["imageData"]; //Get the image from flash file
byte[] photo = Convert.FromBase64String(strPhoto);
string dirUrl = "~/Uploads/cuc_Picture/";
string dirPath = Server.MapPath(dirUrl);
if (!Directory.Exists(dirPath))
{
Directory.CreateDirectory(dirPath);
}
FileStream fs = new FileStream(dirPath+"St_Pic.jpg", FileMode.OpenOrCreate, FileAccess.Write);
BinaryWriter br = new BinaryWriter(fs);
br.Write(photo);
br.Flush();
br.Close();
fs.Close();
string camimg = dirPath + "St_Pic.jpg";
Session["imagePath"] = camimg;
}
catch (Exception Ex)
{
}
}
示例8: Start
// Use this for initialization
void Start()
{
var path = Application.dataPath + "/" + "ranki.txt";
if (!File.Exists(path))
{
{
FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
BinaryWriter writer = new BinaryWriter(fs);
if (writer != null)
{
writer.Write(100000);
writer.Close();
}
}
}
{
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(fs);
if (reader != null)
{
var i = reader.ReadInt32();
reader.Close();
Debug.Log(i);
}
}
}
示例9: Write
public void Write (float[] clipData, WaveFormatChunk format, FileStream stream)
{
WaveHeader header = new WaveHeader ();
WaveDataChunk data = new WaveDataChunk ();
data.shortArray = new short[clipData.Length];
for (int i = 0; i < clipData.Length; i++)
data.shortArray [i] = (short)(clipData [i] * 32767);
data.dwChunkSize = (uint)(data.shortArray.Length * (format.wBitsPerSample / 8));
BinaryWriter writer = new BinaryWriter (stream);
writer.Write (header.sGroupID.ToCharArray ());
writer.Write (header.dwFileLength);
writer.Write (header.sRiffType.ToCharArray ());
writer.Write (format.sChunkID.ToCharArray ());
writer.Write (format.dwChunkSize);
writer.Write (format.wFormatTag);
writer.Write (format.wChannels);
writer.Write (format.dwSamplesPerSec);
writer.Write (format.dwAvgBytesPerSec);
writer.Write (format.wBlockAlign);
writer.Write (format.wBitsPerSample);
writer.Write (data.sChunkID.ToCharArray ());
writer.Write (data.dwChunkSize);
foreach (short dataPoint in data.shortArray) {
writer.Write (dataPoint);
}
writer.Seek (4, SeekOrigin.Begin);
uint filesize = (uint)writer.BaseStream.Length;
writer.Write (filesize - 8);
writer.Close ();
}
示例10: ExtractFile
public static void ExtractFile(ListViewFileItem lvi, string exeName, string outName)
{
//extract file in ListViewFileItem
FileStream fsIn = null;
BinaryReader brIn = null;
FileStream fsOut = null;
BinaryWriter bwOut = null;
try
{
fsIn = new FileStream(exeName, FileMode.Open);
brIn = new BinaryReader(fsIn);
fsOut = new FileStream(outName, FileMode.Create);
bwOut = new BinaryWriter(fsOut);
fsIn.Seek(lvi.Offset, SeekOrigin.Begin);
bwOut.Write(brIn.ReadBytes(lvi.Size));
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (brIn != null)
brIn.Close();
if (fsIn != null)
fsIn.Close();
if (bwOut != null)
bwOut.Close();
if (fsOut != null)
fsOut.Close();
}
}
示例11: ReadBlob
// read the BLOB into file "cs-parser2.cs"
public static void ReadBlob (OracleConnection connection)
{
if (File.Exists(outfilename) == true) {
Console.WriteLine("Filename already exists: " + outfilename);
return;
}
OracleCommand rcmd = connection.CreateCommand ();
rcmd.CommandText = "SELECT BLOB_COLUMN FROM BLOBTEST";
OracleDataReader reader2 = rcmd.ExecuteReader ();
if (!reader2.Read ())
Console.WriteLine ("ERROR: RECORD NOT FOUND");
Console.WriteLine (" TESTING OracleLob OBJECT 2...");
OracleLob lob2 = reader2.GetOracleLob (0);
Console.WriteLine (" LENGTH: {0}", lob2.Length);
Console.WriteLine (" CHUNK SIZE: {0}", lob2.ChunkSize);
byte[] lobvalue = (byte[]) lob2.Value;
if (ByteArrayCompare(bytes1, lobvalue) == true)
Console.WriteLine("bytes1 and bytes2 are equal: good");
else
Console.WriteLine("bytes1 and bytes2 are not equal: bad");
FileStream fs = new FileStream(outfilename, FileMode.CreateNew);
BinaryWriter w = new BinaryWriter(fs);
w.Write(lobvalue);
w.Close();
fs.Close();
lob2.Close ();
reader2.Close ();
}
示例12: ExecuteSaveFontTexture
public static void ExecuteSaveFontTexture()
{
Texture2D tex = Selection.activeObject as Texture2D;
if (tex == null)
{
EditorUtility.DisplayDialog("No texture selected", "Please select a texture", "Cancel");
return;
}
if (tex.format != TextureFormat.Alpha8)
{
EditorUtility.DisplayDialog("Wrong format", "Texture must be in uncompressed Alpha8 format", "Cancel");
return;
}
// Convert Alpha8 texture to ARGB32 texture so it can be saved as a PNG
var texPixels = tex.GetPixels();
var tex2 = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, false);
tex2.SetPixels(texPixels);
// Save texture (WriteAllBytes is not used here in order to keep compatibility with Unity iPhone)
var texBytes = tex2.EncodeToPNG();
var fileName = EditorUtility.SaveFilePanel("Save font texture", "", "font Texture", "png");
if (fileName.Length > 0)
{
FileStream f = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
BinaryWriter b = new BinaryWriter(f);
for (var i = 0; i < texBytes.Length; i++) b.Write(texBytes[i]);
b.Close();
}
GameObject.DestroyImmediate(tex2);
}
示例13: GetResourcesFrameRender
public static void GetResourcesFrameRender(Dictionary<string, string> taskdetails)
{
FileStream fs;
BinaryWriter bw;
Dictionary<string, string> response = XMLRPC.Instance.getFrameRenderResources(Convert.ToInt32(taskdetails["projid"]));
string resourcefilepath = "resources" + Config.Instance.Slash() + response["filename"];
//Open File for writing
fs = new FileStream(resourcefilepath, FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(fs);
bw.Write(Convert.FromBase64String(response["data"]));
bw.Flush();
bw.Close();
fs.Close();
//Is the file a archive.. then unpack it
if (Path.GetExtension(response["filename"]) == ".zip")
{
Archive oArchive = new Archive(resourcefilepath);
oArchive.Extract("resources");
}
}
示例14: Start
public void Start()
{
this.allotedReadingTime = 9;
FileStream fs;
if (!File.Exists("scenes.bin"))
{
fs = new FileStream("scenes.bin", FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write("In November 11, 2015, a barangay hall as well as three houses were gutted by a fire which was reportedly caused by an electrical short circuit\r\nfire\r\nFour families were left homesless after an unattended open flame may have caused the fire that started at 5:37 A.M.\r\nfire\r\nSeven rooms of a three-story old boarding house were damaged in an early morning fire. Electrical misuse is being looked into as a possible cause of the fire.\r\nfire\r\nThree houses were damaged in a fire which was caused by an unattended candle.\r\nfire\r\nAn eight-year-old girl died in a fire. Fire investigators said the fire may have been caused by a lighted candle that fell onto a bed.\r\fire\r\nA morning fire razed a two-storey house and a two-door apartment and damanged another house. The fire was cause by two children who were playing with matches at the second floor.\r\nfire\r\n");
bw.Close();
fs.Close();
}
fs = new FileStream("scenes.bin", FileMode.Open);
StreamReader str = new StreamReader (fs);
while (!str.EndOfStream){
preventiveLine.Add(new Preventive{message = str.ReadLine(), element = str.ReadLine()});
}
Debug.Log(preventiveLine.Count + "Size");
//Debug.Log(preventiveLine.Count+" all");
if (this.size == 0){
this.randomNumber = Random.Range(0, preventiveLine.Count);
scene[this.size] = this.randomNumber;
this.size++;
Debug.Log("size is zero and now "+ this.size);
}
else{
this.proceed = false;
do
{
this.randomNumber = Random.Range(0, preventiveLine.Count);
for (int x = 0; x <= this.size ; x++)
{
if (scene[x] == this.randomNumber){
Debug.Log("same number index "+ x);
this.proceed = true;
}
}
if (this.proceed)
{
Debug.Log("Cant proceed");
this.proceed = false;
}
else {
Debug.Log("display");
this.proceed = true;
scene[this.size] = this.randomNumber;
this.size++;
}
} while (proceed != true);
}
Debug.Log(this.size+ " array size");
}
示例15: Start
// Use this for initialization
void Start()
{
FileStream fs = new FileStream ("test.dem",FileMode.Create, FileAccess.Write);
BinaryWriter bw = new BinaryWriter (fs);
StreamReader sr = new StreamReader ("36814.xyz");
ArrayList height = new ArrayList ();
int[] regionMin = new int[2];
int[] regionMax = new int[2];
string[] words = (sr.ReadLine()).Split (' ');
float interval = 90;
Int32 X = (int)Convert.ToDouble (words [0]);
Int32 Y = (int)Convert.ToDouble (words [1]);
height.Add (words [2]);
regionMax [0] = regionMin [0] = X;
regionMax [1] = regionMin [1] = Y;
while (sr.Peek() >= 0) {
words = (sr.ReadLine()).Split (' ');
X = (int)Convert.ToDouble (words [0]);
Y = (int)Convert.ToDouble (words [1]);
height.Add (words [2]);
if(regionMax[0]<X)
regionMax[0] = X;
if(regionMin[0]>X)
regionMin[0] = X;
if(regionMax[1] <Y)
regionMax[1] = Y;
if(regionMin[1] > Y)
regionMin[1] = Y;
}
bw.Write (interval);
bw.Write (regionMin [0]);
bw.Write (regionMin [1]);
bw.Write (regionMax [0]);
bw.Write (regionMax[1]);
for (int i=0; i<height.Count; i++) {
bw.Write(Convert.ToDouble(height[i]));
}
//bw.Write (Convert.ToDouble(words[0]));
//bw.Write (Convert.ToDouble(words[1]));
/*FileStream fs2 = new FileStream ("test.dem", FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader (fs2);
Console.WriteLine (br.ReadDouble());
Console.WriteLine (br.ReadDouble());*/
sr.Close ();
bw.Close ();
fs.Close ();
}