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


C# FileInfo.ReadAllText方法代码示例

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


在下文中一共展示了FileInfo.ReadAllText方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ApplicationControl_DragDrop

        private void ApplicationControl_DragDrop(object sender, DragEventArgs e)
        {
            label1.Text = "DragDrop";

            //e.Data.GetFormats().WithEach(
            //    f =>
            //    {
            //        label1.Text += "\n" + f;
            //    }
            //);

            // just a path
            // jsc: fixme
            //(e.Data.GetData("FileDrop") as string[]).WithEach(


            var FileDrop = (string[])e.Data.GetData("FileDrop");


            FileDrop.WithEach(
                path =>
                {
                    label1.Text += "\n" + path;

                    if (File.Exists(path))
                    {
                        var f = new FileInfo(path);

                        label1.Text += "\n is a file " + f.Length + " bytes";

                        if (path.EndsWith(".txt"))
                        {
                            //new ScriptCoreLib.JavaScript.DOM.FileReader);

                            // await?
                            f.ReadAllText(
                                text =>
                                {
                                    label1.Text += "\n " + text;
                                }
                            );


                        }
                    }
                }
            );


        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:50,代码来源:ApplicationControl.cs

示例2: ReadAllText

        public void ReadAllText()
        {
            // Type
            var @this = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Examples_System_IO_FileInfo_ReadAllText.txt"));

            // Intialization
            using (FileStream stream = @this.Create())
            {
                byte[] byteToWrites = Encoding.Default.GetBytes("Fizz" + Environment.NewLine + "Buzz");
                stream.Write(byteToWrites, 0, byteToWrites.Length);
            }

            // Examples
            string result = @this.ReadAllText(); // return "Fizz" + Environment.NewLine + "Buzz";

            // Unit Test
            Assert.AreEqual("Fizz" + Environment.NewLine + "Buzz", result);
        }
开发者ID:ChuangYang,项目名称:Z.ExtensionMethods,代码行数:18,代码来源:FileInfo.ReadAllText.cs

示例3: ReadFileContents

 private string ReadFileContents(FileInfo file)
 {
     return file.ReadAllText(Encoding.UTF8);
 }
开发者ID:eaardal,项目名称:delbert,代码行数:4,代码来源:PageActor.cs

示例4: OnTransactionImport

        protected virtual void OnTransactionImport(FileInfo file)
        {
            JsonException e;

            var o = Json.Decode(file.ReadAllText(), out e);

            if (e != null)
            {
                User.SendMessage(e.ToString());

                Refresh(true);
                return;
            }

            var list = new List<DonationTransaction>();

            DonationTransaction trans;

            string id, email, notes, extra;
            double total, time;
            long credit;
            int version;
            TransactionState state;
            IAccount account;

            var stateType = typeof(TransactionState);

            if (o is IEnumerable<object>)
            {
                var col = ((IEnumerable<object>)o).OfType<IDictionary<string, object>>();

                foreach (var obj in col)
                {
                    /*try
                    {*/

                    id = (string)obj.GetValue("id");
                    state = (TransactionState)Enum.Parse(stateType, (string)obj.GetValue("state"), true);
                    account = Accounts.GetAccount((string)obj.GetValue("account"));
                    email = (string)obj.GetValue("email");
                    total = (double)obj.GetValue("total");
                    credit = (long)(double)obj.GetValue("credit");
                    time = (double)obj.GetValue("time");
                    version = (int)(double)obj.GetValue("version");
                    notes = (string)obj.GetValue("notes");
                    extra = (string)obj.GetValue("extra");

                    trans = CreateTransaction(id, state, account, email, total, credit, time, version, notes, extra);
                    /*}
                    catch
                    {
                        trans = null;
                    }*/

                    if (trans != null)
                    {
                        list.Add(trans);
                    }
                }
            }
            else if (o is IDictionary<string, object>)
            {
                var obj = (IDictionary<string, object>)o;

                /*try
                {*/
                id = (string)obj.GetValue("id");
                state = (TransactionState)Enum.Parse(stateType, (string)obj.GetValue("state"), true);
                account = Accounts.GetAccount((string)obj.GetValue("account"));
                email = (string)obj.GetValue("email");
                total = (double)obj.GetValue("total");
                credit = (long)(double)obj.GetValue("credit");
                time = (double)obj.GetValue("time");
                version = (int)(double)obj.GetValue("version");
                notes = (string)obj.GetValue("notes");
                extra = (string)obj.GetValue("extra");

                trans = CreateTransaction(id, state, account, email, total, credit, time, version, notes, extra);
                /*}
                catch
                {
                    trans = null;
                }*/

                if (trans != null)
                {
                    list.Add(trans);
                }
            }

            var count = 0;

            if (list.Count > 0)
            {
                DonationProfile p;
                DonationTransaction ot;

                foreach (var g in list.Where(t => t.Account != null).ToLookup(t => t.Account, t => t))
                {
                    p = AutoDonate.EnsureProfile(g.Key);
//.........这里部分代码省略.........
开发者ID:Vita-Nex,项目名称:Core,代码行数:101,代码来源:AdminUI.cs


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