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


C# IO.FileStream类代码示例

本文整理汇总了C#中System.IO.FileStream的典型用法代码示例。如果您正苦于以下问题:C# System.IO.FileStream类的具体用法?C# System.IO.FileStream怎么用?C# System.IO.FileStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


System.IO.FileStream类属于命名空间,在下文中一共展示了System.IO.FileStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunTime

        private static void RunTime()
        {
            TimeOptions options = new TimeOptions();
            string[] timeArgs = new string[] { "-v", "-o", "/path/to/file", "-a", "--", "--some--", "useless", "noise" };
            options.Initialize(timeArgs);
            /* TimeOptions processing to be added */

            string format = options.format;
            if (options.portability) {
                if (options.verbose) {
                    Console.WriteLine("Setting portable format.");
                }
                format = PORTABLE_FORMAT;
            }

            System.IO.StreamWriter writer = null;
            if (options.outputFile != null && System.IO.File.Exists(options.outputFile)) {
                var fileStream = new System.IO.FileStream(options.outputFile, options.append ? System.IO.FileMode.Append : System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
                writer = new System.IO.StreamWriter(fileStream);
                if (options.verbose) {
                    Console.WriteLine("Output will be redirected to file.");
                }
            }
            else if (options.verbose) {
                Console.WriteLine("Output will be printed to standart output.");
            }

            DoCoreTask(options.Arguments, writer, format);

            if (writer != null) {
                writer.Flush();
                writer.Close();
            }
        }
开发者ID:elenfant,项目名称:mff-programming-practices,代码行数:34,代码来源:time.cs

示例2: CreateReportAsPDF

        public void CreateReportAsPDF(long? orderID, long? orderProductID, string fileName)
        {

            try
            {
                this.SP_MaterialDetailsTableAdapter.Fill(this.OrderManagerDBDataSet.SP_MaterialDetails, orderProductID, orderID);
                this.SP_MaterialOtherCostDetailsTableAdapter.Fill(this.OrderManagerDBOtherCostDataSet.SP_MaterialOtherCostDetails, orderProductID);

                // Variables
                Warning[] warnings;
                string[] streamIds;
                string mimeType = string.Empty;
                string encoding = string.Empty;
                string extension = string.Empty;


                // Setup the report viewer object and get the array of bytes
                byte[] bytes = reportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

                using (System.IO.FileStream sw = new System.IO.FileStream(fileName, System.IO.FileMode.Create))
                {
                    sw.Write(bytes, 0, bytes.Length);
                    sw.Close();
                }
            }
            catch (Exception ex)
            {

            }
        }
开发者ID:venkateshmani,项目名称:trinity,代码行数:30,代码来源:BudgetReportControl.cs

示例3: GetBuildNumber

        //Code PES
        private string GetBuildNumber()
        {
            string strBuildNumber = string.Empty, timestamp = string.Empty;
            string filePath = System.Reflection.Assembly.GetCallingAssembly().Location;
            const int c_PeHeaderOffset = 60;
            const int c_LinkerTimestampOffset = 8;
            byte[] b = new byte[2048];
            System.IO.Stream s = null;

            try
            {
                s = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                s.Read(b, 0, 2048);
            }
            finally
            {
                if (s != null)
                {
                    s.Close();
                }
            }

            int i = System.BitConverter.ToInt32(b, c_PeHeaderOffset);
            int secondsSince1970 = System.BitConverter.ToInt32(b, i + c_LinkerTimestampOffset);
            DateTime dtDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            dtDate = dtDate.AddSeconds(secondsSince1970);
            dtDate = dtDate.ToLocalTime();
            timestamp = dtDate.ToString("yyyyMMddHHmmss");
            if (timestamp == string.Empty)
            { timestamp = "UNKOWN!"; }
            strBuildNumber = "Build  : " + timestamp;
            return strBuildNumber;
        }
开发者ID:santoshsaha,项目名称:AxiomCS-Ribbon,代码行数:34,代码来源:About.xaml.cs

示例4: Save

        protected override void Save()
        {
            if (!this.infoLoaded)
                return;

            RGSSTable table = new RGSSTable(this.Size.Width, this.Size.Height, this.Layers.Count);
            List<MapLayer> truth = new List<MapLayer>(this.Layers);
            if (truth.Count == 4)
            {
                MapLayer layer = truth[2];
                truth.Remove(layer);
                truth.Add(layer);
            }
            for (int z = 0; z < truth.Count; z++)
            {
                for (int x = 0; x < this.Size.Width; x++)
                {
                    for (int y = 0; y < this.Size.Height; y++)
                    {
                        table[x, y, z] = truth[z].Data[x, y];
                    }
                }
            }
            raw.InstanceVariable["@data"] = table;

            using (var fs = new System.IO.FileStream(this.filename, System.IO.FileMode.Create, System.IO.FileAccess.Write))
            {
                NekoKun.Serialization.RubyMarshal.RubyMarshal.Dump(fs, raw);
            }
        }
开发者ID:NekoProject,项目名称:NekoKun,代码行数:30,代码来源:MapFile.cs

示例5: CheckUploadByTwoByte

        /// <summary>
        /// 根据文件的前2个字节进行判断文件类型  ---说明255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar
        /// </summary>
        /// <param name="hpf"></param>
        /// <param name="code">文件的前2个字节转化出来的小数</param>
        /// <returns></returns>
        public bool CheckUploadByTwoByte(HttpPostedFile hpf, Int64 code)
        {
            System.IO.FileStream fs = new System.IO.FileStream(hpf.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader r = new System.IO.BinaryReader(fs);
            string fileclass = "";
            byte buffer;
            try
            {
                buffer = r.ReadByte();
                fileclass = buffer.ToString();
                buffer = r.ReadByte();
                fileclass += buffer.ToString();

            }
            catch
            {

            }
            r.Close();
            fs.Close();
            //
            //if (fileclass == code.ToString())
            //{
            //    return true;
            //}
            //else
            //{
            //    return false;
            //}
            return (fileclass == code.ToString());
        }
开发者ID:cj1324,项目名称:hanchenproject,代码行数:37,代码来源:UploadHelper.cs

示例6: RetrieveLinkerTimestamp

        private DateTime RetrieveLinkerTimestamp()
        {
            string filePath = System.Reflection.Assembly.GetCallingAssembly().Location;
            const int c_PeHeaderOffset = 60;
            const int c_LinkerTimestampOffset = 8;
            byte[] b = new byte[2048];
            System.IO.Stream s = null;

            try
            {
                s = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                s.Read(b, 0, 2048);
            }
            finally
            {
                if (s != null)
                {
                    s.Close();
                }
            }

            int i = System.BitConverter.ToInt32(b, c_PeHeaderOffset);
            int secondsSince1970 = System.BitConverter.ToInt32(b, i + c_LinkerTimestampOffset);
            DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0);
            dt = dt.AddSeconds(secondsSince1970);
            dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours);
            return dt;
        }
开发者ID:philoushka,项目名称:MediaSync,代码行数:28,代码来源:About.cs

示例7: DownloadFile

        //下载网络文件
        /// <summary>
        /// 下载网络文件 带进度条
        /// </summary>
        /// <param name="URL"></param>
        /// <param name="fileName"></param>
        /// <param name="progressBar1"></param>
        /// <returns></returns>
        public static bool DownloadFile(string URL, string fileName,ProgressBar progressBar1)
        {
            try
            {
                System.Net.HttpWebRequest httpWebRequest1 = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL);
                System.Net.HttpWebResponse httpWebResponse1 = (System.Net.HttpWebResponse)httpWebRequest1.GetResponse();

                long totalLength = httpWebResponse1.ContentLength;
                progressBar1.Maximum = (int)totalLength;

                System.IO.Stream stream1 = httpWebResponse1.GetResponseStream();
                System.IO.Stream stream2 = new System.IO.FileStream(fileName, System.IO.FileMode.Create);

                long currentLength = 0;
                byte[] by = new byte[1024];
                int osize = stream1.Read(by, 0, (int)by.Length);
                while (osize > 0)
                {
                    currentLength = osize + currentLength;
                    stream2.Write(by, 0, osize);

                    progressBar1.Value = (int)currentLength;
                    osize = stream1.Read(by, 0, (int)by.Length);
                }

                stream2.Close();
                stream1.Close();

                return (currentLength == totalLength);
            }
            catch
            {
                return false;
            }
        }
开发者ID:450640526,项目名称:HtmExplorer,代码行数:43,代码来源:HttpClass.cs

示例8: InitializeTwitter

        public void InitializeTwitter()
        {
            try
            {
                System.Xml.Serialization.XmlSerializer serializer =
                    new System.Xml.Serialization.XmlSerializer(typeof(saveSettings));
                System.IO.FileStream fs = new System.IO.FileStream(
                    @"settings.xml", System.IO.FileMode.Open);
                saveSettings setting = (saveSettings)serializer.Deserialize(fs);
                fs.Close();
                textBox1.Enabled = false;
                //accToken = setting.AccToken;
                token.AccessToken = setting.AccToken;
                //accTokenSec = setting.AccTokenSec;
                token.AccessTokenSecret = setting.AccTokenSec;

                var Stream = new TwitterStream(token, "Feedertter", null);

                StatusCreatedCallback statusCreatedCallback = new StatusCreatedCallback(StatusCreatedCallback);
                RawJsonCallback rawJsonCallback = new RawJsonCallback(RawJsonCallback);

                Stream.StartUserStream(null, null,
                    /*(x) => { label1.Text += x.Text; }*/
                    statusCreatedCallback,
                    null, null, null, null, rawJsonCallback);
            }
            catch
            {
                Process.Start(OAuthUtility.BuildAuthorizationUri(req.Token).ToString());
            }

            //Process.Start(OAuthUtility.BuildAuthorizationUri(req.Token).ToString());
        }
开发者ID:syamoji,项目名称:ASG-software,代码行数:33,代码来源:Form1.cs

示例9: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //Открываем файл картинки...
                System.IO.FileStream fs = new System.IO.FileStream(openFileDialog1.FileName, System.IO.FileMode.Open);
                System.Drawing.Image img = System.Drawing.Image.FromStream(fs);
                fs.Close();
                //Помещаем исходное изображение в PictureBox1
                pictureBox1.Image = img;

                var bmp = new Bitmap(img);
                label1.Text = "";
                label1.Text = label1.Text + DateTime.Now.Second.ToString() + "." + DateTime.Now.Millisecond.ToString() + " - "; //Время начала обработки (секунды и миллисекунды).
                //Преобразуем картинку
                MakeGray(bmp);
                //Crop(bmp, new Rectangle(0, 0, bmp.Height, bmp.Width));
                Bitmap cropBmp = bmp.Clone(new Rectangle(0, 0, bmp.Width / 2, bmp.Height / 2), bmp.PixelFormat);
                label1.Text = label1.Text + DateTime.Now.Second.ToString() + "." + DateTime.Now.Millisecond.ToString(); //Время окончания обработки (секунды и миллисекунды).
                //Помещаем преобразованное изображение в PictureBox2
                pictureBox2.Image = cropBmp;
                Bitmap cropcloneBmp = cropBmp.Clone(new Rectangle(0, 0, cropBmp.Width, cropBmp.Height), cropBmp.PixelFormat);
                MakeGray(cropcloneBmp);
                //Crop(bmp, new Rectangle(0, 0, bmp.Height, bmp.Width));
                Bitmap cropnewBmp = cropcloneBmp.Clone(new Rectangle(0, 0, cropcloneBmp.Width / 2, cropcloneBmp.Height / 2), cropcloneBmp.PixelFormat);
                label1.Text = label1.Text + DateTime.Now.Second.ToString() + "." + DateTime.Now.Millisecond.ToString(); //Время окончания обработки (секунды и миллисекунды).
                //Помещаем преобразованное изображение в PictureBox2
                pictureBox3.Image = cropnewBmp;
            }

        }
开发者ID:Pashahasband,项目名称:SpaceKurs,代码行数:31,代码来源:Form1.cs

示例10: parse

        public static MidiData parse(FileStream input_file_stream)
        {
            var input_binary_reader = new BinaryReader(input_file_stream);

            HeaderChunk header_chunk;
            ushort number_of_tracks;
            {
                var header_chunk_ID = stringEncoder.GetString(input_binary_reader.ReadBytes(4));
                var header_chunk_size = BitConverter.ToInt32(input_binary_reader.ReadBytes(4).Reverse().ToArray<byte>(), 0);
                var header_chunk_data = input_binary_reader.ReadBytes(header_chunk_size);

                var format_type = BitConverter.ToUInt16(header_chunk_data.Take(2).Reverse().ToArray<byte>(), 0);
                number_of_tracks = BitConverter.ToUInt16(header_chunk_data.Skip(2).Take(2).Reverse().ToArray<byte>(), 0);
                var time_division = BitConverter.ToUInt16(header_chunk_data.Skip(4).Take(2).Reverse().ToArray<byte>(), 0);

                header_chunk = new HeaderChunk(format_type, time_division);
            }

            var tracks =
                Enumerable.Range(0, number_of_tracks)
                .Select(track_number =>
                {
                    var track_chunk_ID = stringEncoder.GetString(input_binary_reader.ReadBytes(4));
                    var track_chunk_size = BitConverter.ToInt32(input_binary_reader.ReadBytes(4).Reverse().ToArray<byte>(), 0);
                    var track_chunk_data = input_binary_reader.ReadBytes(track_chunk_size);

                    return Tuple.Create(track_chunk_size, track_chunk_data);
                }).ToList()
                .Select(raw_track => new TrackChunk(parse_events(raw_track.Item2, raw_track.Item1)));

            return new MidiData(header_chunk, tracks);
        }
开发者ID:OpaqueMegane,项目名称:Unity-Midi-Parser,代码行数:32,代码来源:FileParser.cs

示例11: CreateSketchesPath

        /// <summary>
        /// Returns the path to the sketch image just created
        /// <param name="mask">Mask image of the button</param>
        /// <param name="texture">Texture image of the item</param>
        /// <param name="nameSketch">Name of the image to create</param>
        public static string CreateSketchesPath(string mask, string texture, string nameSketch)
        {
            MagickImage Mask = new MagickImage(mask);

            MagickImage Texture = new MagickImage(texture);

            Texture.Crop(Mask.Width, Mask.Height);

            Texture.Composite(Mask, CompositeOperator.CopyAlpha);
            Mask.Composite(Texture, CompositeOperator.Multiply);
            MagickImage sketch = Mask;

            try
            {
                // sketch.Write(Helpers.ResourcesHelper.SketchesPath() + nameSketch);
                string p = Helpers.ResourcesHelper.SketchesPath() + nameSketch;
                System.IO.Stream s = new System.IO.FileStream(p, System.IO.FileMode.Create);

                sketch.Write(s);
                s.Close();
            }
            catch (MagickException ex)
            {
                string s= ex.Message;
            }
            catch
            {

            }
            sketch.Dispose();
            sketch = null;
            string path = Helpers.ResourcesHelper.SketchesPath() + nameSketch;
            return path;
        }
开发者ID:Amebus,项目名称:KillersWearsPrada,代码行数:39,代码来源:SketchHelper.cs

示例12: SaveToExcel

        public static void SaveToExcel(Microsoft.Reporting.WinForms.ReportViewer reportviewer, string outputfilename)
        {
            string deviceinfo = null;
            string mimetype = null;
            string encoding = null;
            string filenamextension = null;
            string[] streams;
            Microsoft.Reporting.WinForms.Warning[] warnings;

            string format = "Excel";

            var bytes = reportviewer.LocalReport.Render(
                format,
                deviceinfo,
                out mimetype,
                out encoding,
                out filenamextension,
                out streams,
                out warnings);


            using (var fs = new System.IO.FileStream(outputfilename, System.IO.FileMode.Create))
            {
                fs.Write(bytes, 0, bytes.Length);
                fs.Close();
            }
        }
开发者ID:saveenr,项目名称:saveenr,代码行数:27,代码来源:ReportViewerForm.cs

示例13: button1_Click

 private void button1_Click(object sender, RoutedEventArgs e)
 {
     SaveFileDialog dialog = new SaveFileDialog();
     dialog.FileName = "result.csv";
     dialog.Filter = "CSVファイル(*.csv)|*.csv|全てのファイル(*.*)|*.*";
     dialog.OverwritePrompt = true;
     dialog.CheckPathExists = true;
     bool? res = dialog.ShowDialog();
     if (res.HasValue && res.Value)
     {
         try
         {
             if (mainWin.fileWriter != null) mainWin.fileWriter.Flush();
             System.IO.Stream fstream = dialog.OpenFile();
             System.IO.Stream fstreamAppend = new System.IO.FileStream(dialog.FileName+"-log.csv", System.IO.FileMode.OpenOrCreate);
             if (fstream != null && fstreamAppend != null)
             {
                 textBox1.Text = dialog.FileName;
                 mainWin.fileWriter = new System.IO.StreamWriter(fstream);
                 mainWin.logWriter = new System.IO.StreamWriter(fstreamAppend);
             }
         }
         catch (Exception exp)
         {
             MessageBox.Show(exp.ToString());
         }
     }
 }
开发者ID:einbrain,项目名称:WPFDemoServer,代码行数:28,代码来源:Window1.xaml.cs

示例14: Load

        public void Load()
        {
            System.IO.FileStream file = new System.IO.FileStream("data.dat",System.IO.FileMode.Open ) ;
            Byte[] buffer1 = System.BitConverter.GetBytes( Existe[0] ) ;
            Byte[] buffer2 = System.BitConverter.GetBytes( Left[0] ) ;
            Byte[] buffer3 = System.BitConverter.GetBytes( Top[0] ) ;
            Byte[] buffer4 = System.BitConverter.GetBytes( Color[0].ToArgb() ) ;
            Byte[] buffer5 = System.Text.Encoding.BigEndianUnicode.GetBytes( Text[0], 0 , Text[0].Length ) ;

            Byte[] bufferM1 = System.BitConverter.GetBytes( MainLeft ) ;
            Byte[] bufferM2 = System.BitConverter.GetBytes( MainTop ) ;
            file.Read( bufferM1, 0, bufferM1.Length ) ;
            MainLeft = System.BitConverter.ToInt32( bufferM1 , 0 ) ;
            file.Read( bufferM2, 0, bufferM2.Length ) ;
            MainTop = System.BitConverter.ToInt32( bufferM2 , 0 ) ;

            for ( int i = 0 ; i < MAX_POSTS ; i++ )
            {
                file.Read( buffer1, 0, buffer1.Length ) ;
                Existe[i] = System.BitConverter.ToBoolean( buffer1 , 0 ) ;
                file.Read( buffer2, 0, buffer2.Length ) ;
                Left[i] = System.BitConverter.ToInt32( buffer2 , 0 ) ;
                file.Read( buffer3, 0, buffer3.Length ) ;
                Top[i] = System.BitConverter.ToInt32( buffer3 , 0 ) ;
                file.Read( buffer4, 0, buffer4.Length ) ;
                Color[i] = System.Drawing.Color.FromArgb( System.BitConverter.ToInt32(buffer4, 0 ) ) ;
                file.Read( buffer5, 0, buffer5.Length ) ;
                Text[i] = System.Text.Encoding.BigEndianUnicode.GetChars( buffer5 ) ;
            }
            file.Close() ;
        }
开发者ID:riseven,项目名称:PostIt,代码行数:31,代码来源:Data.cs

示例15: Add3

        // GET: Api/Post/Add3
        public JsonResult Add3()
        {
            PostModel model = new PostModel();
            model.PDate = DateTime.Now;

            string fileName = Server.MapPath("~/App_Data/test3.json");
            model.PText = fileName;

            System.Runtime.Serialization.Json.DataContractJsonSerializer ser =
                new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(PostModel));

            System.IO.MemoryStream stream1 = new System.IO.MemoryStream();

            ser.WriteObject(stream1, model);

            using (System.IO.FileStream f2 = new System.IO.FileStream(fileName, System.IO.FileMode.Create))
            {
                byte[] jsonArray = stream1.ToArray();

                using (System.IO.Compression.GZipStream gz =
                    new System.IO.Compression.GZipStream(f2, System.IO.Compression.CompressionMode.Compress))
                {
                    gz.Write(jsonArray, 0, jsonArray.Length);
                }
            }

            return Json(model, JsonRequestBehavior.AllowGet);
        }
开发者ID:DMSysBG,项目名称:PostStore,代码行数:29,代码来源:PostController.cs


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