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


C# FileInfo.WriteAllText方法代码示例

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


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

示例1: Main

    public static int Main(String[] args)
    {
        var ant_launcher_template = @"%ANT_HOME%\lib\ant-launcher.jar";
        var ant_launcher = ant_launcher_template.Expand();
        if (!File.Exists(ant_launcher)) {
          Console.WriteLine(String.Format("Ant launcher not found at {0} (expanded from {1})", ant_launcher, ant_launcher_template));
          return -1;
        }

        var mini = args.Contains("/mini");
        var maxi = args.Contains("/maxi");
        var reg = args.Contains("/reg") || args.Contains("/register");
        if (mini && maxi) {
          Console.WriteLine("Options /mini and /maxi contradict each other.");
          return -1;
        }

        var f_profile = new FileInfo("%SCRIPTS_HOME%".Expand() + "\\" + "ant.profile");
        if (!f_profile.Exists) f_profile.WriteAllText(maxiProfile);
        var profile = mini ? miniProfile : maxi ? maxiProfile : f_profile.ReadAllText();
        if (reg) {
          f_profile.WriteAllText(profile);
          return 0;
        }

        var yourkit = args.Contains("/yourkit");
        if (yourkit) {
          profile += @" -agentpath:""C:\Program Files (x86)\YourKit Java Profiler 11.0.0\bin\win64\yjpagent.dll=sampling""";
        }

        var ant_args = new List<String>();
        ant_args.Add("-classpath \"" + ant_launcher + "\"");
        ant_args.Add("org.apache.tools.ant.launch.Launcher");
        args.Where(arg => !arg.StartsWith("/")).ToList().ForEach(ant_args.Add);

        var psi = new ProcessStartInfo();
        psi.FileName = @"%JAVA_HOME%\bin\java.exe".Expand();
        psi.Arguments = String.Join(" ", ant_args.ToArray());
        psi.EnvironmentVariables["ANT_OPTS"] = profile;
        psi.UseShellExecute = false;

        var p = Process.Start(psi);
        p.WaitForExit();
        return p.ExitCode;
    }
开发者ID:xeno-by,项目名称:dotwindows,代码行数:45,代码来源:ant.cs

示例2: Main


//.........这里部分代码省略.........
          if (file.Exists) dir = file.Directory;

          var dir_as_sublimepath = dir.FullName;
          dir_as_sublimepath = dir_as_sublimepath.Replace("\\", "/");
          dir_as_sublimepath = dir_as_sublimepath.Replace(":/", "/");
          dir_as_sublimepath = "/" + dir_as_sublimepath;

          lines.Add("    {");
          lines.Add("      \"path\": \"" + dir_as_sublimepath + "\"");
          lines.Add("    }");
          if (i != args.Length - 1) lines[lines.Count - 1] = lines[lines.Count - 1] + ",";
        }
        lines.Add("  ]");
        lines.Add("}");
        project.WriteAllLines(lines);

        lines = new List<String>();
        lines.Add("{");
        lines.Add("  \"build_system\": \"Packages/User/Myke.sublime-build\",");
        lines.Add("  \"show_minimap\": false,");
        lines.Add("  \"show_open_files\": true,");
        lines.Add("  \"show_tabs\": true,");
        lines.Add("  \"side_bar_visible\": true,");
        lines.Add("  \"side_bar_width\": 256.0,");
        lines.Add("  \"status_bar_visible\": true");
        lines.Add("}");
        var workspace = new FileInfo(Path.ChangeExtension(project.FullName, "sublime-workspace"));
        workspace.WriteAllLines(lines);

        args = new []{"--project", "\"" + project.FullName + "\""}.Concat(args).ToArray();
          } else {
        var file0 = new FileInfo(args[0]);
        var dir0 = new DirectoryInfo(args[0]);
        if (file0.Exists) dir0 = file0.Directory;

        if (file0.Exists || dir0.Exists || args[0].Contains(".")) {
          // don't do any postprocessing of args => open in current instance of sublime
          // upd. the hack below is needed because "sublime file_name" is currently broken!!
          var sublimeNotYetOpen = Process.GetProcesses().Where(process => process.ProcessName != null && process.ProcessName.EndsWith("sublime_text")).Count() == 0;
          if (sublimeNotYetOpen) {
            var project = new FileInfo(projects + "\\kep.sublime-project");
            args = new []{"--project", "\"" + project.FullName + "\"", args[0]};
          }
        } else {
          var project = new FileInfo(projects + "\\" + args[0] + ".sublime-project");
          if (!project.Exists) {
            MessageBox.Show(String.Format("Project \"{0}\" not found. \r\n\r\n" +
                                          "Could not find project file {1}.", args[0], project),
                                          "Sublime Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
          } else {
            if (args.Length == 2 && (args[1].ToLower() == "/reg" || args[1].ToLower() == "/register")) {
              projects.GetFiles("*.is.default").ToList().ForEach(file => file.Delete());
              var default_file = new FileInfo(Path.ChangeExtension(project.FullName, "is.default"));
              default_file.WriteAllText("");
              args = args.Take(1).Concat(args.Skip(2)).ToArray();
            }

            if (args.Length != 1) return;
            args = new []{"--project", "\"" + project.FullName + "\""};
          }
        }
          }
        }

        if (args.Length == 0) {
          MessageBox.Show("No files, directories or projects specified. \r\n\r\nTo make sublime run without any arguments " +
                      "open a default project, first register the project via \"sublime <project> /reg\".",
                      "Sublime Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
          return;
        }

        var session = new FileInfo(home + @"\Settings\Session.sublime_session");
        if (session.Exists) {
          var iof = args.ToList().IndexOf("--project");
          var project = args[iof + 1];

          var lines = session.ReadAllLines();
          lines = lines.Select(line => {
        if (line.Contains("\"workspace_name\"")) {
          var sublimepath = project.Substring(1, project.Length - 2);
          sublimepath = sublimepath.Replace("\\", "/");
          sublimepath = sublimepath.Replace(":/", "/");
          sublimepath = "/" + sublimepath;
          var linex = "      \"workspace_name\": \"" + sublimepath + "\"";
          if (line.Trim().EndsWith(",")) linex += ",";
          return linex;
        } else {
          return line;
        }
          }).ToList();
          session.WriteAllLines(lines);
        }

        //    if (MessageBox.Show("About to start sublime with args: " + String.Join(" ", args), "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes) {
          Process.Start(sublime, String.Join(" ", args));
          Thread.Sleep(50);
          PostprocessSublimeWindow();
        //    }
    }
开发者ID:xeno-by,项目名称:dotwindows,代码行数:101,代码来源:sublime.cs


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