本文整理汇总了C#中FileStream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# FileStream.Close方法的具体用法?C# FileStream.Close怎么用?C# FileStream.Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileStream
的用法示例。
在下文中一共展示了FileStream.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static int Main()
{
byte [] buf = new byte [1];
AsyncCallback ac = new AsyncCallback (async_callback);
IAsyncResult ar;
int sum0 = 0;
FileStream s = new FileStream ("async_read.cs", FileMode.Open);
s.Position = 0;
sum0 = 0;
while (s.Read (buf, 0, 1) == 1)
sum0 += buf [0];
s.Position = 0;
do {
ar = s.BeginRead (buf, 0, 1, ac, buf);
} while (s.EndRead (ar) == 1);
sum -= buf [0];
Thread.Sleep (100);
s.Close ();
Console.WriteLine ("CSUM: " + sum + " " + sum0);
if (sum != sum0)
return 1;
return 0;
}
示例2: AppendResultsToFile
public void AppendResultsToFile(String Name, double TotalTime)
{
FileStream file;
file = new FileStream(Name, FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(file);
sw.Write("***************************************\n");
sw.Write("Total | No Subs| %Total |%No Subs| Name\n");
foreach (CNamedTimer NamedTimer in m_NamedTimerArray)
{
if (NamedTimer.GetTotalSeconds() > 0)
{
String OutString;
OutString = String.Format("{0:0.0000}", NamedTimer.GetTotalSeconds())
+ " | " + String.Format("{0:0.0000}", NamedTimer.GetTotalSecondsExcludingSubroutines())
+ " | " + String.Format("{0:00.00}", System.Math.Min(99.99, NamedTimer.GetTotalSeconds() / TotalTime * 100)) + "%"
+ " | " + String.Format("{0:00.00}", NamedTimer.GetTotalSecondsExcludingSubroutines() / TotalTime * 100) + "%"
+ " | "
+ NamedTimer.m_Name;
OutString += " (" + NamedTimer.m_Counter.ToString() + ")\n";
sw.Write(OutString);
}
}
sw.Write("\n\n");
sw.Close();
file.Close();
}
示例3: 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);
}
示例4: saveCurrentName
public void saveCurrentName(){
FileStream stream = null;
try{
XmlSerializer serializer = new XmlSerializer(typeof(ScreenName));
stream = new FileStream(screenNameFileLocation, FileMode.OpenOrCreate);
serializer.Serialize(stream, screenName);
stream.Close();
} catch(Exception ex){
if(stream != null)
stream.Close();
//throw ex;
}
}
示例5: saveCurrentOptions
public void saveCurrentOptions(){
FileStream stream = null;
try{
XmlSerializer serializer = new XmlSerializer(typeof(OptionsInfo));
stream = new FileStream(optionsFileLocation, FileMode.OpenOrCreate);
serializer.Serialize(stream, newOptions); // new options to disk here
stream.Close();
} catch(Exception ex){
Debug.LogError(ex.ToString());
if(stream != null)
stream.Close();
}
currentOptions = newOptions;
}
示例6: loadCurrentOptions
/// <summary>
/// Loads the currentOptions from disk.
/// </summary>
public void loadCurrentOptions(){
FileStream stream = null;
try{
XmlSerializer serializer = new XmlSerializer(typeof(OptionsInfo));
stream = new FileStream(optionsFileLocation, FileMode.Open);
OptionsInfo container = (OptionsInfo)serializer.Deserialize(stream);
currentOptions = container;
stream.Close();
//}catch(Exception ex){
} catch{
if(stream != null)
stream.Close();
//Debug.LogError(ex.ToString());
}
}
示例7: Open
public static GOBFile Open(string path)
{
//Debug.Log("GOBFile.Open(" + path + ")");
FileStream fs = null;
try { fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); } catch {}
if (fs == null) {
Debug.LogError("OpenRead(\"" + path + "\") failed.");
return null;
}
BinaryReader br = new BinaryReader(fs);
try {
byte[] id = new byte[4];
if (br.Read(id, 0, 4) != 4) {
Debug.LogError("Failed to read GOB header in file " + path + ".");
fs.Close();
return null;
}
if ((id[0] != 71) || (id[1] != 79) || (id[2] != 66) || (id[3] != 0xA)) {
fs.Close();
Debug.LogError("\"" + path + "\" is not a GOB file.");
return null;
}
int dirOfs = br.ReadInt32();
br.BaseStream.Position = (long)dirOfs;
int numFiles = br.ReadInt32();
GOBFile gob = new GOBFile();
byte[] name = new byte[13];
for (int i = 0; i < numFiles; ++i) {
File file = File.Read(br, name);
gob._dir.Add(file.Name, file);
// Debug.Log (file.Name);
}
gob._file = br;
return gob;
} catch {
using (br) {}
}
return null;
}
示例8: Assemble
private static void Assemble(List<string> files, string destinationDirectory)
{
string fileOutputPath = destinationDirectory + "assembled" + "." + matches[0].Groups[2];
var fsSource = new FileStream(fileOutputPath, FileMode.Create);
fsSource.Close();
using (fsSource = new FileStream(fileOutputPath, FileMode.Append))
{
foreach (var filePart in files)
{
using (var partSource = new FileStream(filePart, FileMode.Open))
{
Byte[] bytePart = new byte[4096];
while (true)
{
int readBytes = partSource.Read(bytePart, 0, bytePart.Length);
if (readBytes == 0)
{
break;
}
fsSource.Write(bytePart, 0, readBytes);
}
}
}
}
}
示例9: Load
public static bool Load(Chunk chunk)
{
string saveFile = SaveLocation(chunk.world.worldName);
saveFile += FileName(chunk.pos);
if (!File.Exists(saveFile))
return false;
try
{
IFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream(saveFile, FileMode.Open);
Save save = (Save)formatter.Deserialize(stream);
//Once the blocks in the save are added they're marked as unmodified so
//as not to trigger a new save on unload unless new blocks are added.
for (int i =0; i< save.blocks.Length; i++)
{
Block placeBlock = save.blocks[i];
placeBlock.modified = false;
chunk.SetBlock(save.positions[i], placeBlock, false);
}
stream.Close();
}
catch (Exception ex)
{
Debug.LogError(ex);
}
return true;
}
示例10: UploadFile
public void UploadFile(RemoteFileInfo request)
{
try
{
FileGonnaGo objFileUpload = new FileGonnaGo();
if (objFileUpload.impersonateValidUser())
{
FileStream targetStream = null;
Stream sourceStream = request.FileByteStream;
string uploadFolder = objFileServerImpersonation.FileServerPath();
string filePath = Path.Combine(uploadFolder, request.FileName);
using (targetStream = new FileStream(filePath, FileMode.Create,
FileAccess.Write, FileShare.None))
{
const int bufferLen = 21474833;
byte[] buffer = new byte[bufferLen];
int count = 0;
while ((count = sourceStream.Read(buffer, 0, bufferLen)) > 0)
{
targetStream.Write(buffer, 0, count);
}
targetStream.Close();
sourceStream.Close();
}
objFileUpload.undoImpersonation();
}
}
catch (Exception ex)
{
WCFFILESERVER.FileService.LogException(string.Empty, ex);
throw;
}
}
示例11: Serialize
void Serialize(string filename){
// normalizes the data to the {0.0-1.0f} interval and saves as xml
Waveform w = new Waveform();
w.name = filename;
w.cycles=1;
w.signal = signal;
w.mode=filename;
w.normalRate = normal;
w.samples = dataPoints.Count;
float scale = dataMax-dataMin;
if ( scale == 0.0f )
scale = 1.0f;
w.data = new float[dataPoints.Count];
for (int i=0;i< dataPoints.Count;i++){
w.data[i]= (dataPoints[i].point-dataMin)/scale;
}
XmlSerializer serializer = new XmlSerializer(typeof(Waveform));
FileStream stream = new FileStream(filename + ".xml", FileMode.Create);
serializer.Serialize(stream, w);
stream.Close();
}
示例12: Deserialize
public void Deserialize(string path)
{
XmlSerializer serializer = new XmlSerializer(typeof(Edge));
FileStream stream = new FileStream(path, FileMode.Open);
copy(serializer.Deserialize(stream) as Edge);
stream.Close();
}
示例13: OnPostprocessAllAssets
public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
foreach (string asset in importedAssets)
{
if (asset.EndsWith(".resx"))
{
string filePath = asset.Substring(0, asset.Length - Path.GetFileName(asset).Length) + "Generated Assets/";
string newFileName = filePath + Path.GetFileNameWithoutExtension(asset) + ".txt";
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
//Delete the file if it already exists
if(File.Exists(newFileName))
{
File.Delete(newFileName);
}
StreamReader reader = new StreamReader(asset);
string fileData = reader.ReadToEnd();
reader.Close();
FileStream resourceFile = new FileStream(newFileName, FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter writer = new StreamWriter(resourceFile);
writer.Write(fileData);
writer.Close();
resourceFile.Close();
AssetDatabase.Refresh(ImportAssetOptions.Default);
}
}
}
示例14: WriteDust
public void WriteDust(string path)
{
XmlSerializer serializer = new XmlSerializer(typeof(ScriptDustItemsContainer));
FileStream stream = new FileStream(path, FileMode.Create);
serializer.Serialize(stream, this);
stream.Close();
}
示例15: getFile
private void getFile()
{
TcpClient client = list.AcceptTcpClient();
StreamReader sr = new StreamReader(client.GetStream());
string rd = sr.ReadLine();
string v = rd.Substring(rd.LastIndexOf('.') + 1);
Debug.Log("reading file. Length: " + v + " bytes.");
TcpClient client2 = list2.AcceptTcpClient();
Debug.Log("reading from rnetworkStream");
NetworkStream rnetworkStream = client2.GetStream();
FileStream fileStream = new FileStream(receiveFileName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
long filezie = int.Parse(v);
int byteSize = 0;
byte[] downBuffer = new byte[2048];
while ((byteSize = rnetworkStream.Read(downBuffer, 0, downBuffer.Length)) > 0)
{
fileStream.Write(downBuffer, 0, byteSize);
}
fileStream.Close();
rnetworkStream.Close();
client.Close ();
client2.Close ();
Debug.Log("Finish geting file");
}