本文整理汇总了C#中System.IO.FileInfo.Close方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.Close方法的具体用法?C# FileInfo.Close怎么用?C# FileInfo.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileInfo
的用法示例。
在下文中一共展示了FileInfo.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsFileLocked
protected bool IsFileLocked(string file)
{
//check that problem is not in destination file
if (File.Exists(file) == true)
{
FileStream stream = null;
try
{
stream = new FileInfo(file).Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
//stream = File.Open(file, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
}
catch (Exception ex2)
{
//_log.WriteLog(ex2, "Error in checking whether file is locked " + file);
int errorCode = Marshal.GetHRForException(ex2) & ((1 << 16) - 1);
if ((ex2 is IOException) && (errorCode == ERROR_SHARING_VIOLATION || errorCode == ERROR_LOCK_VIOLATION))
{
return true;
}
}
finally
{
if (stream != null)
stream.Close();
}
}
return false;
}
示例2: DownloadFromFtp
public static bool DownloadFromFtp(string fileName)
{
bool ret = true;
var dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string path = Path.Combine(dirName, fileName);
try
{
var wc = new WebClient { Credentials = new NetworkCredential("solidk", "KSolid") };
var fileStream = new FileInfo(path).Create();
//string downloadPath = Path.Combine("ftp://194.84.146.5/ForDealers",fileName);
string downloadPath = Path.Combine(Furniture.Helpers.FtpAccess.resultFtp+"ForDealers", fileName);
var str = wc.OpenRead(downloadPath);
const int bufferSize = 1024;
var buffer = new byte[bufferSize];
int readCount = str.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
fileStream.Write(buffer, 0, readCount);
readCount = str.Read(buffer, 0, bufferSize);
}
str.Close();
fileStream.Close();
wc.Dispose();
}
catch
{
ret = false;
}
return ret;
}
示例3: WriteLine_Nothing
public void WriteLine_Nothing()
{
csvReaderWriter.Open(TestOutputFile, CSVReaderWriter.Mode.Write);
csvReaderWriter.WriteLine();
csvReaderWriter.Close();
StreamReader reader = new FileInfo(TestOutputFile).OpenText();
Assert.That(reader.ReadToEnd(), Is.EqualTo("\r\n"));
reader.Close();
}
示例4: ReadFileUTF8
public string ReadFileUTF8(string filePath)
{
string ret;
using (var stream = new FileInfo(filePath).OpenText())
{
ret = stream.ReadToEnd();
stream.Close();
}
return ret;
}
示例5: create
/// <summary>
/// 新建
/// </summary>
public void create()
{
FileStream fs = new FileInfo(file).Create();
fs.Close();
StreamWriter sw = new StreamWriter(file);
sw.Write("{");
sw.Write("}");
sw.Flush();
sw.Close();
}
示例6: openFileDialog1_FileOk
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
if (openFileDialog1.CheckFileExists)
{
this.Activate();
FileStream fileStream = new FileInfo(openFileDialog1.FileName).OpenRead();
previewPictureBox.Image = Bitmap.FromStream(fileStream);
fileStream.Close();
trixelButton.Enabled = true;
trackBar1.Enabled = true;
trackBar1.Minimum = 1;
trackBar1.Maximum = previewPictureBox.Image.Width > previewPictureBox.Image.Height ? previewPictureBox.Image.Width : previewPictureBox.Image.Height;
sizeLabel.Text = "" + trackBar1.Value;
}
}
示例7: FileStreamTest
internal static void FileStreamTest()
{
Console.WriteLine("文件流读写测试:\n");
//不同的方式打开文件流
FileStream testFile = new FileStream("test.txt", FileMode.Create, FileAccess.ReadWrite);
//FileStream testFile2 = new FileInfo("text2.txt").Open(FileMode.OpenOrCreate, FileAccess.ReadWrite);
//写文件
testFile.WriteByte(50);
testFile.Write(new byte[] { 10, 20, 30, 40 }, 0, 4);
testFile.Close();
//读文件
testFile = new FileInfo("test.txt").OpenRead();
byte[] buffer = new byte[testFile.Length];
testFile.Read(buffer, 0, buffer.Length);
new List<byte>(buffer).ForEach((e) => Console.Write(e));
Console.WriteLine();
testFile.Close();
}
示例8: BundleStorageManager
public BundleStorageManager(string storagePath, string bundleId)
{
_storagePath = storagePath;
_bundleId = bundleId;
_dataFolderPath = Path.Combine(storagePath, StorageFolderName);
Directory.CreateDirectory(_storagePath); // create if necessary
Directory.CreateDirectory(_dataFolderPath); // create if necessary
CleanUpExpiredData();
TransactionId = GetTransactionId();
BundlePath = Path.Combine(_dataFolderPath, String.Format("{0}.bundle", TransactionId));
if (!File.Exists(BundlePath))
{
var fs = new FileInfo(BundlePath).Create();
fs.Close();
}
}
示例9: VideoViewHandler
public VideoViewHandler()
{
if (!File.Exists(customVideoViews))
{
File.Copy(defaultVideoViews, customVideoViews);
}
try
{
using (FileStream fileStream = new FileInfo(customVideoViews).OpenRead())
{
SoapFormatter formatter = new SoapFormatter();
ArrayList viewlist = (ArrayList)formatter.Deserialize(fileStream);
foreach (ViewDefinition view in viewlist)
{
views.Add(view);
}
fileStream.Close();
}
}
catch (Exception) {}
}
示例10: cmdSave_Click
private void cmdSave_Click(object sender, EventArgs e)
{
StreamWriter sw = new FileInfo(_installPath+"\\"+cboFile.Text).CreateText();
sw.Write(txtLST.Text);
sw.Close();
}
示例11: saveMsgtolocal
private void saveMsgtolocal()
{
FileStream stream = new FileInfo(this.sMsgFile).Open(FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
string s = DateTime.Now.ToString() + " " + base.txtCarNo.Text.Trim() + " : " + this.txtMsgValue.Text.Trim() + "\r\n";
byte[] bytes = Encoding.Default.GetBytes(s);
stream.Write(bytes, 0, bytes.Length);
stream.Flush();
stream.Close();
}
示例12: loadUsers
//文件系统
int loadUsers()
{
try
{
StreamReader lsr = File.OpenText(".\\users.txt");
int n = 2;
int i;
//label1.Text = "Find " + n.ToString() + " Users";
for (i = 0; i < n; i++)
{
string temp = lsr.ReadLine();
userName.Add(temp);
int m = Convert.ToInt16(lsr.ReadLine());
int j;
for (j = 0; j < m; j++)
{
string tfilepath = lsr.ReadLine();
FileStream stream = new FileInfo(tfilepath).OpenRead();
Byte[] buffer = new Byte[stream.Length];
//从流中读取字节块并将该数据写入给定缓冲区buffer中
stream.Read(buffer, 0, Convert.ToInt32(stream.Length));
FaceTemplate ftem;
ftem.templateData = buffer;
faceTemplates.Add(ftem);
stream.Close();
}
List<FaceTemplate> atemp = new List<FaceTemplate>(faceTemplates.ToArray());
UserTemplates.Add(atemp);
faceTemplates.Clear();
}
lsr.Close();
Console.WriteLine("Load OK");
Console.WriteLine(UserTemplates.Count.ToString());
Console.WriteLine(userName.Count.ToString());
return 0;
}
catch
{
Console.WriteLine("No user Stored");
return 1;
}
}
示例13: menuTest_Click
void menuTest_Click(object sender, EventArgs e)
{
if (_config.ConfirmTest)
{
DialogResult res = new TestDialog(_config).ShowDialog();
if (res == DialogResult.Cancel) return;
}
// prep stuff
menuSave_Click("menuTest_Click", new EventArgs());
if (_config.VerifyTest && !_config.Verify) Common.RunVerify(_mission.MissionPath, _config.VerifyLocation);
/*Version os = Environment.OSVersion.Version;
bool isWin7 = (os.Major == 6 && os.Minor == 1);
System.Diagnostics.Process explorer = null;
int restart = 1;
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", true);*/
// configure XvT/BoP
int index = 0;
string path = (_mission.IsBop ? _config.BopPath : _config.XvtPath);
while (File.Exists(path + "\\test" + index + "0.plt")) index++;
string pilot = "\\test" + index + "0.plt";
string bopPilot = "\\test" + index + "0.pl2";
string lst = "\\Train\\IMPERIAL.LST";
string backup = "\\Train\\IMPERIAL_" + index + ".bak";
File.Copy(Application.StartupPath + "\\xvttest0.plt", _config.XvtPath + pilot);
if (_config.BopInstalled) File.Copy(Application.StartupPath + "\\xvttest0.pl2", _config.BopPath + bopPilot, true);
// XvT pilot edit
FileStream pilotFile = File.OpenWrite(_config.XvtPath + pilot);
pilotFile.Position = 4;
char[] indexBytes = index.ToString().ToCharArray();
new BinaryWriter(pilotFile).Write(indexBytes);
for (int i = (int)pilotFile.Position; i < 0xC; i++) pilotFile.WriteByte(0);
pilotFile.Close();
// BoP pilot edit
if (_config.BopInstalled)
{
pilotFile = File.OpenWrite(_config.BopPath + bopPilot);
pilotFile.Position = 4;
indexBytes = index.ToString().ToCharArray();
new BinaryWriter(pilotFile).Write(indexBytes);
for (int i = (int)pilotFile.Position; i < 0xC; i++) pilotFile.WriteByte(0);
pilotFile.Close();
}
// configure XvT
System.Diagnostics.Process xvt = new System.Diagnostics.Process();
xvt.StartInfo.FileName = path + "\\Z_XVT__.exe";
xvt.StartInfo.Arguments = "/skipintro";
xvt.StartInfo.UseShellExecute = false;
xvt.StartInfo.WorkingDirectory = path;
File.Copy(path + lst, path + backup, true);
StreamReader sr = File.OpenText(_config.XvtPath + "\\Config.cfg");
string contents = sr.ReadToEnd();
sr.Close();
int lastpilot = contents.IndexOf("lastpilot ") + 10;
int nextline = contents.IndexOf("\r\n", lastpilot);
string modified = contents.Substring(0, lastpilot) + "test" + index + contents.Substring(nextline);
StreamWriter sw = new FileInfo(_config.XvtPath + "\\Config.cfg").CreateText();
sw.Write(modified);
sw.Close();
if (_config.BopInstalled)
{
sr = File.OpenText(_config.BopPath + "\\config2.cfg");
contents = sr.ReadToEnd();
sr.Close();
lastpilot = contents.IndexOf("lastpilot ") + 10;
nextline = contents.IndexOf("\r\n", lastpilot);
modified = contents.Substring(0, lastpilot) + "test" + index + contents.Substring(nextline);
sw = new FileInfo(_config.BopPath + "\\config2.cfg").CreateText();
sw.Write(modified);
sw.Close();
}
sr = File.OpenText(path + lst);
contents = sr.ReadToEnd();
sr.Close();
string[] expanded = contents.Replace("\r\n", "\0").Split('\0');
expanded[4] = _mission.MissionFileName;
expanded[5] = "YOGEME: " + expanded[4];
modified = String.Join("\r\n", expanded);
sw = new FileInfo(path + lst).CreateText();
sw.Write(modified);
sw.Close();
/*if (isWin7) // explorer kill so colors work right
{
restart = (int)key.GetValue("AutoRestartShell", 1);
key.SetValue("AutoRestartShell", 0, Microsoft.Win32.RegistryValueKind.DWord);
explorer = System.Diagnostics.Process.GetProcessesByName("explorer")[0];
explorer.Kill();
explorer.WaitForExit();
}*/
xvt.Start();
System.Threading.Thread.Sleep(1000);
System.Diagnostics.Process[] runningXvts = System.Diagnostics.Process.GetProcessesByName("Z_XVT__");
while (runningXvts.Length > 0)
{
Application.DoEvents();
System.Diagnostics.Debug.WriteLine("sleeping...");
//.........这里部分代码省略.........
示例14: WriteTemporalSkindleExecutable
/// <summary>
/// Creates a temporal executable of Skindle from the embedded resource
/// </summary>
/// <param name="skindleEXEStream">Skindle's stream</param>
private void WriteTemporalSkindleExecutable(Stream skindleEXEStream)
{
var outputStream = new FileInfo(_skindlePath).OpenWrite();
// read from embedded resource and write to output file
const int size = 4096;
byte[] bytes = new byte[4096];
int numBytes;
while ((numBytes = skindleEXEStream.Read(bytes, 0, size)) > 0)
{
outputStream.Write(bytes, 0, numBytes);
}
outputStream.Close();
skindleEXEStream.Close();
}
示例15: Downloading
private void Downloading(WebClient wc, string neededLibrary, long sz)
{
if (!Directory.Exists(_mainDir.Root + "MrDoors_Solid_Update"))
Directory.CreateDirectory(_mainDir.Root + "MrDoors_Solid_Update");
string fullDownloadingPath = _mainDir.Root + "MrDoors_Solid_Update\\" + neededLibrary;
if (File.Exists(fullDownloadingPath))
{
if (new FileInfo(fullDownloadingPath).Length == sz)
return;
}
var fileStream = new FileInfo(fullDownloadingPath).Create();
label3.Visible = true;
DateTime dt1 = DateTime.Now;
var str = wc.OpenRead(Properties.Settings.Default.FtpPath + "/" + neededLibrary);
const int bufferSize = 1024;
var z = (int)(sz / bufferSize);
var buffer = new byte[bufferSize];
int readCount = str.Read(buffer, 0, bufferSize);
progressBar1.Minimum = 1;
progressBar1.Value = 1;
progressBar1.Maximum = z;
int i = 0;
int countBytePerSec = 0;
long commonByte = 0;
while (readCount > 0)
{
DateTime dt2 = DateTime.Now;
fileStream.Write(buffer, 0, readCount);
commonByte += readCount;
countBytePerSec += readCount;
readCount = str.Read(buffer, 0, bufferSize);
var dt = dt2 - dt1;
if (dt.TotalSeconds > i)
{
long lasttime = ((sz - commonByte) / countBytePerSec) * 10000000;
var f = new TimeSpan(lasttime);
string time;
if (f.Hours > 0)
{
if (f.Hours == 1)
{
time = f.Hours + " час " + f.Minutes + " минуты " + f.Seconds + " секунд";
}
else
{
if (f.Hours > 1 && f.Hours < 5)
time = f.Hours + " часа " + f.Minutes + " минуты " + f.Seconds + " секунд";
else
time = f.Hours + " часов " + f.Minutes + " минуты " + f.Seconds + " секунд";
}
}
else
if (f.Minutes > 0)
time = f.Minutes + " минут " + f.Seconds + " секунд";
else
time = f.Seconds + " секунд";
countBytePerSec = countBytePerSec / 1024;
if (((countBytePerSec) / 1024) > 1)
{
countBytePerSec = countBytePerSec / 1024;
label3.Text = dt.Minutes + @":" + dt.Seconds + @" секунд Скорость: " + countBytePerSec +
@" Мб/с Осталось приблизительно: " + time;
}
else
label3.Text = dt.Minutes + @":" + dt.Seconds + @" секунд Скорость: " + countBytePerSec + @" Кб/с Осталось приблизительно: " + time;
Application.DoEvents();
countBytePerSec = 0;
i++;
}
progressBar1.Increment(1);
}
str.Close();
fileStream.Close();
}