<bdo id='XGdbU'></bdo><ul id='XGdbU'></ul>
  1. <tfoot id='XGdbU'></tfoot>

    <i id='XGdbU'><tr id='XGdbU'><dt id='XGdbU'><q id='XGdbU'><span id='XGdbU'><b id='XGdbU'><form id='XGdbU'><ins id='XGdbU'></ins><ul id='XGdbU'></ul><sub id='XGdbU'></sub></form><legend id='XGdbU'></legend><bdo id='XGdbU'><pre id='XGdbU'><center id='XGdbU'></center></pre></bdo></b><th id='XGdbU'></th></span></q></dt></tr></i><div id='XGdbU'><tfoot id='XGdbU'></tfoot><dl id='XGdbU'><fieldset id='XGdbU'></fieldset></dl></div>
  2. <legend id='XGdbU'><style id='XGdbU'><dir id='XGdbU'><q id='XGdbU'></q></dir></style></legend>

    <small id='XGdbU'></small><noframes id='XGdbU'>

      将格式化的字符串写入文件 - Java

      时间:2023-06-28

      <small id='GPBvB'></small><noframes id='GPBvB'>

        <tbody id='GPBvB'></tbody>
      <legend id='GPBvB'><style id='GPBvB'><dir id='GPBvB'><q id='GPBvB'></q></dir></style></legend>

      <tfoot id='GPBvB'></tfoot>
      • <bdo id='GPBvB'></bdo><ul id='GPBvB'></ul>

                <i id='GPBvB'><tr id='GPBvB'><dt id='GPBvB'><q id='GPBvB'><span id='GPBvB'><b id='GPBvB'><form id='GPBvB'><ins id='GPBvB'></ins><ul id='GPBvB'></ul><sub id='GPBvB'></sub></form><legend id='GPBvB'></legend><bdo id='GPBvB'><pre id='GPBvB'><center id='GPBvB'></center></pre></bdo></b><th id='GPBvB'></th></span></q></dt></tr></i><div id='GPBvB'><tfoot id='GPBvB'></tfoot><dl id='GPBvB'><fieldset id='GPBvB'></fieldset></dl></div>
              1. 本文介绍了将格式化的字符串写入文件 - Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                I have a string that I format with the System.out.format() method, I do something like :

                System.out.format("I = %3d  var = %9.6f", i, myVar);
                

                but when I try to write this formatted string into a file, I only get something like "java.io.PrintStream@84fc8d" in it.

                After looking into the documentation understood that this method is a little like System.out.print() and just return a PrintStream to display (in console for example), so I tried converting it with .toString or String.valueOf() but I get the same result.

                So I was wondering if there is a way to format a string just like the String.out.format() method does, but in a way that will be writable in a file ?

                Here is approximately the code I use (just making the useful parts appear)

                WRITE_MY_LINE(System.out.format(" I = %3d  var = %9.6f", i, myVar).toString());
                //also tried this :
                WRITE_MY_LINE(String.valueOf(System.out.format(" I = %3d  var = %9.6f", i, myVar)));
                
                public static void WRITE_MY_LINE(String line) {
                        buff_out = new BufferedWriter(new FileWriter(ascii_path, true));
                
                        buff_out.append(line);
                        buff_out.newLine();
                        buff_out.flush();
                }
                

                解决方案

                String.format is what you are looking for it returns a String and not a PrintStream like System.out.format.

                Your code should be:

                WRITE_MY_LINE(String.format(" I = %3d  var = %9.6f", i, myVar));
                

                Take a look at Java.lang.String.format() Method for further information.

                这篇关于将格式化的字符串写入文件 - Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:为什么选择“010"?等于 8? 下一篇:带有 dateStyle 和 timeStyle 的 Joda-Time 格式化程序

                相关文章

              2. <small id='634ru'></small><noframes id='634ru'>

                1. <legend id='634ru'><style id='634ru'><dir id='634ru'><q id='634ru'></q></dir></style></legend>

                  <tfoot id='634ru'></tfoot>
                  1. <i id='634ru'><tr id='634ru'><dt id='634ru'><q id='634ru'><span id='634ru'><b id='634ru'><form id='634ru'><ins id='634ru'></ins><ul id='634ru'></ul><sub id='634ru'></sub></form><legend id='634ru'></legend><bdo id='634ru'><pre id='634ru'><center id='634ru'></center></pre></bdo></b><th id='634ru'></th></span></q></dt></tr></i><div id='634ru'><tfoot id='634ru'></tfoot><dl id='634ru'><fieldset id='634ru'></fieldset></dl></div>
                      <bdo id='634ru'></bdo><ul id='634ru'></ul>