本文整理汇总了C#中System.IO.FileInfo.OpenWrite方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.FileInfo.OpenWrite方法的具体用法?C# System.IO.FileInfo.OpenWrite怎么用?C# System.IO.FileInfo.OpenWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileInfo
的用法示例。
在下文中一共展示了System.IO.FileInfo.OpenWrite方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateTempFile
public void CreateTempFile(byte[] buffByte, string path)
{
System.IO.FileStream fs;
System.IO.FileInfo fi = new System.IO.FileInfo(path);
fs = fi.OpenWrite();
fs.Write(buffByte, 0, buffByte.Length);
fs.Close();
}
示例2: IsFileWriteable
public static bool IsFileWriteable(string path) {
if(System.IO.File.Exists(path)){
System.IO.FileInfo fi = new System.IO.FileInfo(path);
fi.OpenWrite();
}
return false;
}
示例3: GetOutputFile
public virtual TextWriter GetOutputFile( Grammar g, string fileName )
{
if ( OutputDirectory == null )
return new StringWriter();
// output directory is a function of where the grammar file lives
// for subdir/T.g, you get subdir here. Well, depends on -o etc...
// But, if this is a .tokens file, then we force the output to
// be the base output directory (or current directory if there is not a -o)
//
#if false
System.IO.DirectoryInfo outputDir;
if ( fileName.EndsWith( CodeGenerator.VOCAB_FILE_EXTENSION ) )
{
if ( haveOutputDir )
{
outputDir = new System.IO.DirectoryInfo( OutputDirectory );
}
else
{
outputDir = new System.IO.DirectoryInfo( "." );
}
}
else
{
outputDir = getOutputDirectory( g.FileName );
}
#else
System.IO.DirectoryInfo outputDir = GetOutputDirectory( g.FileName );
#endif
FileInfo outputFile = new FileInfo( System.IO.Path.Combine( outputDir.FullName, fileName ) );
if ( !outputDir.Exists )
outputDir.Create();
if ( outputFile.Exists )
outputFile.Delete();
GeneratedFiles.Add(outputFile.FullName);
return new System.IO.StreamWriter( new System.IO.BufferedStream( outputFile.OpenWrite() ) );
}
示例4: Save
/// <summary>
/// Saves of the attachment to a file in the given path.
/// </summary>
/// <param name="path">A <see cref="System.String" /> specifying the path on which to save the attachment.</param>
/// <param name="overwrite"><b>true</b> if the destination file can be overwritten; otherwise, <b>false</b>.</param>
/// <returns><see cref="System.IO.FileInfo" /> of the saved file. <b>null</b> when it fails to save.</returns>
/// <remarks>If the file was already saved, the previous <see cref="System.IO.FileInfo" /> is returned.<br />
/// Once the file is successfully saved, the stream is closed and <see cref="SavedFile" /> property is updated.</remarks>
public System.IO.FileInfo Save( System.String path, bool overwrite )
{
if ( path==null || this._name==null )
return null;
if ( this._stream==null ) {
if ( this._saved_file!=null )
return this._saved_file;
else
return null;
}
if ( !this._stream.CanRead ) {
#if LOG
if ( log.IsErrorEnabled )
log.Error(System.String.Concat("The provided stream does not support reading."));
#endif
return null;
}
System.IO.FileInfo file = new System.IO.FileInfo (System.IO.Path.Combine (path, this._name));
if ( !file.Directory.Exists ) {
#if LOG
if ( log.IsErrorEnabled )
log.Error(System.String.Concat("Destination folder [", file.Directory.FullName, "] does not exist"));
#endif
return null;
}
if ( file.Exists ) {
if ( overwrite ) {
try {
file.Delete();
#if LOG
} catch ( System.Exception e ) {
if ( log.IsErrorEnabled )
log.Error(System.String.Concat("Error deleting existing file[", file.FullName, "]"), e);
#else
} catch ( System.Exception ) {
#endif
return null;
}
} else {
#if LOG
if ( log.IsErrorEnabled )
log.Error(System.String.Concat("Destination file [", file.FullName, "] already exists"));
#endif
// Though the file already exists, we set the times
if ( this._mtime!=System.DateTime.MinValue && file.LastWriteTime!=this._mtime )
file.LastWriteTime = this._mtime;
if ( this._ctime!=System.DateTime.MinValue && file.CreationTime!=this._ctime )
file.CreationTime = this._ctime;
return null;
}
}
try {
System.IO.FileStream stream = file.OpenWrite();
this._stream.WriteTo(stream);
stream.Flush();
stream.Close();
this.Close();
if ( this._mtime!=System.DateTime.MinValue )
file.LastWriteTime = this._mtime;
if ( this._ctime!=System.DateTime.MinValue )
file.CreationTime = this._ctime;
this._saved_file = file;
#if LOG
} catch ( System.Exception e ) {
if ( log.IsErrorEnabled )
log.Error(System.String.Concat("Error writting file [", file.FullName, "]"), e);
#else
} catch ( System.Exception ) {
#endif
return null;
}
return file;
}
示例5: ComputeSAT
//.........这里部分代码省略.........
for ( int Y=0; Y < H; Y++ ) {
for ( int X=0; X < TargetWidth; X++ ) {
float CenterX = X * MipPixelSizeX + 0.5f * (MipPixelSizeX-1);
float4 Sum = KernelFactors[0] * BilinearSample( Source, CenterX, Y );
for ( int i=1; i <= KernelSize; i++ ) {
Sum += KernelFactors[i] * BilinearSample( Image, CenterX - i, Y );
Sum += KernelFactors[i] * BilinearSample( Image, CenterX + i, Y );
}
Target[X,Y] = Sum;
}
}
// Perform vertical blur
Source = Target;
Mips[MipLevel] = new float4[TargetWidth,TargetHeight];
Target = Mips[MipLevel];
for ( int X=0; X < TargetWidth; X++ ) {
for ( int Y=0; Y < TargetHeight; Y++ ) {
float CenterY = Y * MipPixelSizeY + 0.5f * (MipPixelSizeY-1);
float4 Sum = KernelFactors[0] * BilinearSample( Source, X, CenterY );
for ( int i=1; i <= KernelSize; i++ ) {
Sum += KernelFactors[i] * BilinearSample( Source, X, CenterY - i );
Sum += KernelFactors[i] * BilinearSample( Source, X, CenterY + i );
}
Target[X,Y] = Sum;
}
}
}
string Pipi = _TargetFileName.FullName;
Pipi = System.IO.Path.GetFileNameWithoutExtension( Pipi ) + ".pipi";
System.IO.FileInfo SimpleTargetFileName2 = new System.IO.FileInfo( Pipi );
using ( System.IO.FileStream S = SimpleTargetFileName2.OpenWrite() )
using ( System.IO.BinaryWriter Wr = new System.IO.BinaryWriter( S ) ) {
Wr.Write( Mips.Length );
for ( int MipLevel=0; MipLevel < Mips.Length; MipLevel++ ) {
float4[,] Mip = Mips[MipLevel];
int MipWidth = Mip.GetLength( 0 );
int MipHeight = Mip.GetLength( 1 );
Wr.Write( MipWidth );
Wr.Write( MipHeight );
for ( int Y=0; Y < MipHeight; Y++ ) {
for ( int X=0; X < MipWidth; X++ ) {
Wr.Write( Mip[X,Y].x );
Wr.Write( Mip[X,Y].y );
Wr.Write( Mip[X,Y].z );
Wr.Write( Mip[X,Y].w );
}
}
}
}
}
// //////////////////////////////////////////////////////////////////////////
// // Build "3D mips" and save as a simple format
// {
// int MaxSize = Math.Max( W, H );
// int MipsCount = (int) (Math.Ceiling( Math.Log( MaxSize+1 ) / Math.Log( 2 ) ));
//
// // 1] Build vertical mips
// float4[][,] VerticalMips = new float4[MipsCount][,];
// VerticalMips[0] = Image;
示例6: Clone
public bool Clone(bool full)
{
if (Workspace != null)
return false;
try
{
if (!full)
{
ProtoBuf.Serializer.SerializeWithLengthPrefix<NetCommand>(Connection.GetStream(), new NetCommand() { Type = NetCommandType.Clone }, ProtoBuf.PrefixStyle.Fixed32);
var clonePack = Utilities.ReceiveEncrypted<ClonePayload>(SharedInfo);
Workspace = Area.InitRemote(BaseDirectory, clonePack, SkipContainmentCheck);
}
else
{
ProtoBuf.Serializer.SerializeWithLengthPrefix<NetCommand>(Connection.GetStream(), new NetCommand() { Type = NetCommandType.FullClone }, ProtoBuf.PrefixStyle.Fixed32);
var response = ProtoBuf.Serializer.DeserializeWithLengthPrefix<NetCommand>(Connection.GetStream(), ProtoBuf.PrefixStyle.Fixed32);
if (response.Type == NetCommandType.Acknowledge)
{
int dbVersion = (int)response.Identifier;
if (!WorkspaceDB.AcceptRemoteDBVersion(dbVersion))
{
Printer.PrintError("Server database version is incompatible (v{0}). Use non-full clone to perform the operation.", dbVersion);
ProtoBuf.Serializer.SerializeWithLengthPrefix<NetCommand>(Connection.GetStream(), new NetCommand() { Type = NetCommandType.Error }, ProtoBuf.PrefixStyle.Fixed32);
return false;
}
else
ProtoBuf.Serializer.SerializeWithLengthPrefix<NetCommand>(Connection.GetStream(), new NetCommand() { Type = NetCommandType.Acknowledge }, ProtoBuf.PrefixStyle.Fixed32);
}
System.IO.FileInfo fsInfo = new System.IO.FileInfo(System.IO.Path.GetRandomFileName());
Printer.PrintMessage("Attempting to import metadata file to temp path {0}", fsInfo.FullName);
var printer = Printer.CreateSimplePrinter("Progress", (obj) =>
{
return string.Format("#b#{0}## received.", Versionr.Utilities.Misc.FormatSizeFriendly((long)obj));
});
try
{
long total = 0;
using (var stream = fsInfo.OpenWrite())
{
while (true)
{
var data = Utilities.ReceiveEncrypted<DataPayload>(SharedInfo);
stream.Write(data.Data, 0, data.Data.Length);
total += data.Data.Length;
printer.Update(total);
if (data.EndOfStream)
break;
}
printer.End(total);
response = ProtoBuf.Serializer.DeserializeWithLengthPrefix<NetCommand>(Connection.GetStream(), ProtoBuf.PrefixStyle.Fixed32);
if (response.Type == NetCommandType.Error)
{
Printer.PrintError("Server failed to clone the database.");
return false;
}
}
Printer.PrintMessage("Metadata written, importing DB.");
Area area = new Area(Area.GetAdminFolderForDirectory(BaseDirectory));
try
{
fsInfo.MoveTo(area.MetadataFile.FullName);
if (!area.ImportDB())
throw new Exception("Couldn't import data.");
Workspace = Area.Load(BaseDirectory);
SharedInfo.Workspace = Workspace;
return true;
}
catch
{
if (area.MetadataFile.Exists)
area.MetadataFile.Delete();
area.AdministrationFolder.Delete();
throw;
}
}
catch
{
if (fsInfo.Exists)
fsInfo.Delete();
return false;
}
}
SharedInfo.Workspace = Workspace;
return true;
}
catch (Exception e)
{
Printer.PrintError(e.ToString());
return false;
}
}
示例7: Main
//.........这里部分代码省略.........
dt = System.IO.File.GetLastWriteTime (tempPath + "\\dummyFile9.txt");
} catch (Exception e) {
exc = e;
} finally {
outFile.WriteLine ("Name: " + tempPath + "\\dummyFile9.txt");
outFile.WriteLine ("Func: " + "System.IO.File.GetLastWriteTime(String)");
outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
outFile.WriteLine ("Time: " + GetTime (now));
outFile.WriteLine ("Retv: " + toString (dt));
outFile.WriteLine ("Errc: " + "");
outFile.WriteLine ("Exce: " + GetException (exc));
}
try {
exc = null;
fs = null;
now = System.DateTime.Now;
fs = System.IO.File.OpenRead (tempPath + "\\dummyFile10.txt");
fs.Close ();
} catch (Exception e) {
exc = e;
} finally {
outFile.WriteLine ("Name: " + tempPath + "\\dummyFile10.txt");
outFile.WriteLine ("Func: " + "System.IO.File.OpenRead(String)");
outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
outFile.WriteLine ("Time: " + GetTime (now));
outFile.WriteLine ("Retv: " + toString (fs));
outFile.WriteLine ("Errc: " + "");
outFile.WriteLine ("Exce: " + GetException (exc));
}
try {
exc = null;
fs = null;
now = System.DateTime.Now;
fs = System.IO.File.OpenWrite (tempPath + "\\dummyFile11.txt");
fs.Close ();
} catch (Exception e) {
exc = e;
} finally {
outFile.WriteLine ("Name: " + tempPath + "\\dummyFile11.txt");
outFile.WriteLine ("Func: " + "System.IO.File.OpenWrite(String)");
outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
outFile.WriteLine ("Time: " + GetTime (now));
outFile.WriteLine ("Retv: " + toString (fs));
outFile.WriteLine ("Errc: " + "");
outFile.WriteLine ("Exce: " + GetException (exc));
}
try {
exc = null;
fs = null;
now = System.DateTime.Now;
fs = System.IO.File.Create (tempPath + "\\testFile1.txt");
fs.Close ();
} catch (Exception e) {
exc = e;
} finally {
outFile.WriteLine ("Name: " + tempPath + "\\testFile1.txt");
outFile.WriteLine ("Func: " + "System.IO.File.Create(String)");
outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
outFile.WriteLine ("Time: " + GetTime (now));
outFile.WriteLine ("Retv: " + toString (fs));
outFile.WriteLine ("Errc: " + "");
outFile.WriteLine ("Exce: " + GetException (exc));
}
try {
exc = null;
fs = null;