本文整理汇总了C#中FileStream.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# FileStream.Flush方法的具体用法?C# FileStream.Flush怎么用?C# FileStream.Flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileStream
的用法示例。
在下文中一共展示了FileStream.Flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ByteArrayToFile
public bool ByteArrayToFile(string _FileName, byte[] _ByteArray)
{
try
{
// Open file for reading
FileStream _FileStream = new FileStream(_FileName, FileMode.Create, FileAccess.Write);
// Writes a block of bytes to this stream using data from a byte array.
_FileStream.Write(_ByteArray, 0, _ByteArray.Length);
_FileStream.Flush();
// close file stream
_FileStream.Close();
return true;
}
catch (Exception _Exception)
{
// Error
Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
}
// error occured, return false
return false;
}
示例2: createVersionFile
static void createVersionFile()
{
string resPath = "C:/Users/Administrator/Desktop/tmp/";
// 获取Res文件夹下所有文件的相对路径和MD5值
string[] files = Directory.GetFiles(resPath, "*", SearchOption.AllDirectories);
StringBuilder versions = new StringBuilder();
for (int i = 0, len = files.Length; i < len; i++)
{
string filePath = files[i];
string extension = filePath.Substring(files[i].LastIndexOf("."));
if (extension == ".unity3d" ||
extension == ".assetbundle")
{
string relativePath = filePath.Replace(resPath, "").Replace("\\", "/");
string md5 = ExportAssetBundles.MD5File(filePath);
versions.Append(relativePath).Append(",").Append(md5).Append("\n");
}
}
// 生成配置文件
FileStream stream = new FileStream(resPath + "version.ver", FileMode.Create);
byte[] data = Encoding.UTF8.GetBytes(versions.ToString());
stream.Write(data, 0, data.Length);
stream.Flush();
stream.Close();
Debug.Log(" 版本文件: " + resPath + "version.ver");
}
示例3: EncryptData
private static void EncryptData(String inName, String outName, byte[] desKey, byte[] desIV)
{
FileStream fs = new FileStream(inName, FileMode.Open, FileAccess.Read);
// Create an instance of the Rijndael cipher
SymmetricAlgorithm aes = Rijndael.Create();
// set the key to be the derivedKey computed above
aes.Key = desKey;
// set the IV to be all zeros
aes.IV = desIV; // arrays are zero-initialized
// now wrap an encryption transform around the filestream
CryptoStream stream1 = new CryptoStream(fs, aes.CreateEncryptor(), CryptoStreamMode.Read);
// The result of reading from stream1 is ciphertext, but we want it
// base64-encoded, so wrap another transform around it
CryptoStream stream2 = new CryptoStream(stream1, new ToBase64Transform(), CryptoStreamMode.Read);
FileStream fsout = new FileStream(outName, FileMode.OpenOrCreate);
byte[] buffer = new byte[1024];
int bytesRead;
do {
bytesRead = stream2.Read(buffer,0,1024);
fsout.Write(buffer,0,bytesRead);
} while (bytesRead > 0);
fsout.Flush();
fsout.Close();
}
示例4: UpdateVersionFile
public static void UpdateVersionFile(string version)
{
try
{
string path = Application.dataPath + "/Resources/Version/";
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
FileStream fs = new FileStream(Application.dataPath + "/Resources/Version/version.txt", FileMode.Create);
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(version);
fs.Write(bytes, 0, bytes.Length);
fs.Flush();
fs.Close();
}
catch (Exception ex)
{
Debug.LogError("ex is:" + ex.ToString());
}
AssetDatabase.Refresh();
}
示例5: WriteFile
public static void WriteFile(string path, int sampleRate, double[] samplesL, double[] samplesR)
{
using (FileStream file = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
{
WriteWav(file, sampleRate, samplesL, samplesR);
file.Flush(true);
}
}
示例6: ReplaceLocalRes
private void ReplaceLocalRes(string fileName, byte[] data)
{
string filePath = LOCAL_RES_PATH + fileName;
FileStream stream = new FileStream(filePath, FileMode.Create);
stream.Write(data, 0, data.Length);
stream.Flush();
stream.Close();
}
示例7: saveFile
private static void saveFile(StringBuilder fileInfoes)
{
string targetPath = GetPath() + "version.txt";
FileStream fs = new FileStream(targetPath, FileMode.Create);
byte[] data = new UTF8Encoding().GetBytes(fileInfoes.ToString());
fs.Write(data, 0, data.Length);
fs.Flush();
fs.Close();
}
示例8: WriteFile
public static void WriteFile(string path, byte[] bytes)
{
path.Replace("\\", "/");
string dir = path.Substring(0, path.LastIndexOf("/"));
CheckPath(dir);
FileStream fs = new FileStream(path, FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Flush();
fs.Close();
fs.Dispose();
}
示例9: Export
/// <summary>
/// DataTable导出到Excel文件
/// </summary>
/// <param name="dtSource">源DataTable</param>
/// <param name="headerTextList">表头摘要信息</param>
/// <param name="strFileName">保存位置</param>
public void Export(DataTable dtSource, List<String> headerTextList, string strFileName)
{
using (MemoryStream ms = Export(dtSource, headerTextList))
{
using (FileStream fs = new FileStream(strFileName, FileMode.Create, FileAccess.Write))
{
byte[] data = ms.ToArray();
fs.Write(data, 0, data.Length);
fs.Flush();
}
}
}
示例10: Main
public static void Main(string[] args) {
byte[] data = {0x00, // begin short
0x01, 0x12,
0x01, // begin string
(byte)'a', (byte)' ', (byte)'t', (byte)'e',
(byte)'s', (byte)'t',
0x02 // end string
};
FileStream fs = new FileStream("data", FileMode.Create, FileAccess.Write, FileShare.Read, 32, false);
fs.Write(data, 0, data.Length);
fs.Flush();
fs.Close();
}
示例11: UpLoadLog
public static void UpLoadLog()
{
m_bIsUpdate = true;
fInfo = new FileStream(datapath,FileMode.Create,FileAccess.Write,FileShare.ReadWrite);
writer = new StreamWriter(fInfo);
writer.Write(LogText);
writer.Flush();
fInfo.Flush();
writer.Close();
fInfo.Close();
WebClient Tmp = new WebClient();
Tmp.UploadFile("http://bbs.enveesoft.com:84/brave/index.php/site/logwrite",datapath);
Debug.Log ("UpLoad_Log");
m_bIsUpdate = false;
}
示例12: Save
public static void Save(Vector3[] info, string fullPath)
{
FileStream fs = new FileStream(fullPath, FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
for (int i = 0; i < info.Length; i++)
{
sw.WriteLine(string.Format("{0:F1}\t {1:F1}\t {2:F1}", info[i].x, info[i].y, info[i].z));
}
fs.Flush();
sw.Close();
fs.Close();
Debug.Log(string.Format(".hmap saved. {0}", fullPath));
}
示例13: DecryptFile
public void DecryptFile(string a_inputFile, string a_outputFile, string a_key)
{
ICryptoTransform decryptor = InitDecrypt(a_key);
FileStream inputFileStream = new FileStream(a_inputFile, FileMode.Open, FileAccess.Read);
CryptoStream decryptStream = new CryptoStream(inputFileStream, decryptor, CryptoStreamMode.Read);
byte[] inputFileData = new byte[(int)inputFileStream.Length];
int decrypt_length = decryptStream.Read(inputFileData, 0, (int)inputFileStream.Length);
FileStream outputFileStream = new FileStream(a_outputFile, FileMode.Create, FileAccess.Write);
outputFileStream.Write(inputFileData, 0, decrypt_length);
outputFileStream.Flush();
decryptStream.Close();
inputFileStream.Close();
outputFileStream.Close();
}
示例14: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
QrEncoder encoder = new QrEncoder(ErrorCorrectionLevel.M);
QrCode qrCode;
encoder.TryEncode("Test", out qrCode);
GraphicsRenderer gRenderer = new GraphicsRenderer(
new FixedModuleSize(2, QuietZoneModules.Two),
Brushes.Black, Brushes.White);
MemoryStream ms = new MemoryStream();
gRenderer.WriteToStream(qrCode.Matrix, ImageFormat.Png, ms);
FileStream file = new FileStream("D:\\qr.png", FileMode.OpenOrCreate);
ms.WriteTo(file);
file.Flush();
file.Close();
}
示例15: Download
/// <summary>
/// 下载文件(断点续传)
/// </summary>
/// <param name="_url">下载地址</param>
/// <param name="_filePath">本地文件存储目录</param>
public void Download(string _url, string _fileDirectory)
{
isStop = false;
thread = new Thread(delegate ()
{
if (!Directory.Exists(_fileDirectory))
Directory.CreateDirectory(_fileDirectory);
string filePath = _fileDirectory + "/" + _url.Substring(_url.LastIndexOf('/') + 1);
if (!File.Exists(filePath))
File.Create(filePath);
FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write);
long fileLength = fileStream.Length;
float totalLength = GetLength(_url);
if (fileLength < totalLength)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(_url);
request.AddRange((int)fileLength);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
fileStream.Seek(fileLength, SeekOrigin.Begin);
Stream httpStream = response.GetResponseStream();
byte[] buffer = new byte[1024];
int length = httpStream.Read(buffer, 0, buffer.Length);
while (length > 0)
{
if (isStop)
break;
fileStream.Write(buffer, 0, length);
fileLength += length;
progress = fileLength / totalLength * 100;
fileStream.Flush();
length = httpStream.Read(buffer, 0, buffer.Length);
}
httpStream.Close();
httpStream.Dispose();
}
else
progress = fileLength / totalLength * 100;
fileStream.Close();
fileStream.Dispose();
});
thread.IsBackground = true;
thread.Start();
}