本文整理汇总了C#中FileStream类的典型用法代码示例。如果您正苦于以下问题:C# FileStream类的具体用法?C# FileStream怎么用?C# FileStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileStream类属于命名空间,在下文中一共展示了FileStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: 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;
}
示例3: SendFileToPrinter
public static bool SendFileToPrinter( string szPrinterName, string szFileName )
{
// Open the file.
FileStream fs = new FileStream(szFileName, FileMode.Open);
// Create a BinaryReader on the file.
BinaryReader br = new BinaryReader(fs);
// Dim an array of bytes big enough to hold the file's contents.
Byte []bytes = new Byte[fs.Length];
bool bSuccess = false;
// Your unmanaged pointer.
IntPtr pUnmanagedBytes = new IntPtr(0);
int nLength;
nLength = Convert.ToInt32(fs.Length);
// Read the contents of the file into the array.
bytes = br.ReadBytes( nLength );
// Allocate some unmanaged memory for those bytes.
pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength);
// Copy the managed byte array into the unmanaged array.
Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength);
// Send the unmanaged bytes to the printer.
bSuccess = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, nLength);
// Free the unmanaged memory that you allocated earlier.
Marshal.FreeCoTaskMem(pUnmanagedBytes);
return bSuccess;
}
示例4: Ctor
// This plug basically forwards all calls to the $$InnerStream$$ stream, which is supplied by the file system.
// public static unsafe void Ctor(String aThis, [FieldAccess(Name = "$$Storage$$")]ref Char[] aStorage, Char[] aChars, int aStartIndex, int aLength,
public static void Ctor(FileStream aThis, string aPathname, FileMode aMode,
[FieldAccess(Name = "$$InnerStream$$")] ref Stream innerStream)
{
Global.mFileSystemDebugger.SendInternal("FileStream.Ctor:");
innerStream = InitializeStream(aPathname, aMode);
}
示例5: Read
private void Read(string filename)
{
XmlSerializer ser=new XmlSerializer(typeof(DataSet));
FileStream fs=new FileStream(filename, FileMode.Open);
DataSet ds;
ds=(DataSet)ser.Deserialize(fs);
fs.Close();
Console.WriteLine("DataSet name: "+ds.DataSetName);
Console.WriteLine("DataSet locale: "+ds.Locale.Name);
foreach(DataTable t in ds.Tables)
{
Console.WriteLine("Table name: "+t.TableName);
Console.WriteLine("Table locale: "+t.Locale.Name);
foreach(DataColumn c in t.Columns)
{
Console.WriteLine("Column name: "+c.ColumnName);
Console.WriteLine("Null allowed? "+c.AllowDBNull);
}
foreach(DataRow r in t.Rows)
{
Console.WriteLine("Row: "+(string)r[0]);
}
}
}
示例6: Assemble
static void Assemble(List<string> files, string destinationDirectory)
{
string fileOutputPath = destinationDirectory + "assembled" + "." + matches[0].Groups[3];
var fsSource = new FileStream(fileOutputPath, FileMode.Create);
fsSource.Close();
using (fsSource = new FileStream(fileOutputPath, FileMode.Append))
{
// reading the file paths of the parts from the files list
foreach (var filePart in files)
{
using (var partSource = new FileStream(filePart, FileMode.Open))
{
using (var compressionStream = new GZipStream(partSource,CompressionMode.Decompress,false))
{
// copy the bytes from part to new assembled file
Byte[] bytePart = new byte[4096];
while (true)
{
int readBytes = compressionStream.Read(bytePart, 0, bytePart.Length);
if (readBytes == 0)
{
break;
}
fsSource.Write(bytePart, 0, readBytes);
}
}
}
}
}
}
示例7: ExportProteinSettings
public void ExportProteinSettings()
{
try
{
CutParametersContainer exportParams = new CutParametersContainer();
foreach (CutObject cuto in SceneManager.Get.CutObjects)
{
CutObjectProperties props = new CutObjectProperties();
props.ProteinTypeParameters = cuto.IngredientCutParameters;
props.Inverse = cuto.Inverse;
props.CutType = (int)cuto.CutType;
props.rotation = cuto.transform.rotation;
props.position = cuto.transform.position;
props.scale = cuto.transform.localScale;
exportParams.CutObjectProps.Add(props);
}
////write
serializer = new XmlSerializer(typeof(CutParametersContainer));
stream = new FileStream(path, FileMode.Create);
serializer.Serialize(stream, exportParams);
stream.Close();
}
catch(Exception e)
{
Debug.Log("export failed: " + e.ToString());
return;
}
Debug.Log("exported cutobject settings to " + path);
}
示例8: OnGUI
//------------------------------------------------------------------------------------------------------------
private void OnGUI()
{
m_MeshFilter = (MeshFilter)EditorGUILayout.ObjectField("MeshFilter", m_MeshFilter, typeof(MeshFilter), true);
if (m_MeshFilter != null)
{
if (GUILayout.Button("Export OBJ"))
{
var lOutputPath = EditorUtility.SaveFilePanel("Save Mesh as OBJ", "", m_MeshFilter.name + ".obj", "obj");
if (File.Exists(lOutputPath))
{
File.Delete(lOutputPath);
}
var lStream = new FileStream(lOutputPath, FileMode.Create);
var lOBJData = m_MeshFilter.sharedMesh.EncodeOBJ();
OBJLoader.ExportOBJ(lOBJData, lStream);
lStream.Close();
}
}
else
{
GUILayout.Label("Please provide a MeshFilter");
}
}
示例9: Write
public void Write(string logfilename, string log, LogType lt)
{
#if UNITY_IPHONE || UNITY_ANDROID
return;
#endif
string filePathName = WriteFile(logfilename);
FileStream fs = new FileStream(filePathName, FileMode.Append);
StreamWriter sw = new StreamWriter(fs);
//开始写入
sw.WriteLine("");
//
string str = "[";
str += System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");//默认当天时间。
str += "]";
str += "\t";
str += lt.ToString();
str += "\t";
str += log;
sw.Write(str);
//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
fs.Close();
}
示例10: SaveToFile
public static void SaveToFile(Level data, string fileName)
{
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream(string.Format("{0}.level", fileName), FileMode.Create, FileAccess.Write, FileShare.Write);
formatter.Serialize(stream, data);
stream.Close();
}
示例11: Slice
static void Slice(string destinationDirectory, int parts)
{
using (var sourceFile = new FileStream(destinationDirectory, FileMode.Open))
{
long partLength = sourceFile.Length / parts;
long lastPartLength = (sourceFile.Length % parts) + (sourceFile.Length / parts);
for (int i = 0; i < parts; i++)
{
using (var destination = new FileStream("../../Part " + (i + 1).ToString() + ".txt", FileMode.Create))
{
byte[] buffer;
if (i == parts - 1)
{
buffer = new byte[lastPartLength];
}
else
{
buffer = new byte[partLength];
}
sourceFile.Read(buffer, 0, buffer.Length);
destination.Write(buffer, 0, buffer.Length);
}
}
}
}
示例12: Load
/// <summary>
/// Loads the SessionDetails object from serialized xml SessionDetails file.
/// </summary>
/// <param name="serializeFileName">file Path of xml serialized SessionDetails object.</param>
/// <returns>SessionDetails object.</returns>
public static SessionDetails Load(string serializeFileName)
{
SessionDetails RetVal = null;
FileStream _IO = null;
if (File.Exists(serializeFileName))
{
try
{
_IO = new FileStream(serializeFileName, FileMode.Open);
XmlSerializer _SRZFrmt = new XmlSerializer(typeof(SessionDetails));
RetVal = (SessionDetails)_SRZFrmt.Deserialize(_IO);
}
catch (System.Runtime.Serialization.SerializationException ex)
{
Global.CreateExceptionString(ex, null);
//throw;
}
finally
{
if (_IO != null)
{
_IO.Flush();
_IO.Close();
}
}
}
return RetVal;
}
示例13: GetPicture
public Stream GetPicture()
{
string fileName = Path.Combine(HostingEnvironment.ApplicationPhysicalPath,"vista.jpg");
FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
System.ServiceModel.Web.WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
return (Stream)fileStream;
}
示例14: Write
public static void Write(FileStream aThis, byte[] aBuffer, int aOffset, int aCount,
[FieldAccess(Name = "$$InnerStream$$")] ref Stream innerStream)
{
Global.mFileSystemDebugger.SendInternal("FileStream.Write:");
innerStream.Write(aBuffer, aOffset, aCount);
}
示例15: Read
public static int Read(FileStream aThis, byte[] aBuffer, int aOffset, int aCount,
[FieldAccess(Name = "$$InnerStream$$")] ref Stream innerStream)
{
Global.mFileSystemDebugger.SendInternal("FileStream.Read:");
return innerStream.Read(aBuffer, aOffset, aCount);
}