当前位置: 首页>>代码示例>>C#>>正文


C# System.IO.FileInfo.OpenWrite方法代码示例

本文整理汇总了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();
 }
开发者ID:callme119,项目名称:civil,代码行数:8,代码来源:WinWordControlEx.cs

示例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;
        }
开发者ID:elrute,项目名称:Triphulcas,代码行数:8,代码来源:File.cs

示例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() ) );
        }
开发者ID:antlr,项目名称:antlrcs,代码行数:41,代码来源:AntlrTool.cs

示例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;
 }
开发者ID:jeske,项目名称:StepsDB-alpha,代码行数:81,代码来源:SharpMessage.cs

示例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;
开发者ID:Patapom,项目名称:GodComplex,代码行数:67,代码来源:AreaLightForm.cs

示例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;
            }
        }
开发者ID:eatplayhate,项目名称:versionr,代码行数:93,代码来源:Client.cs

示例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;
开发者ID:uvbs,项目名称:Holodeck,代码行数:67,代码来源:TestApplication4.cs


注:本文中的System.IO.FileInfo.OpenWrite方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。