<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

      Writing a formatted string to a file - Java(将格式化的字符串写入文件 - Java)

      <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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Lucene Porter Stemmer not public(Lucene Porter Stemmer 未公开)
                How to index pdf, ppt, xl files in lucene (java based or python or php any of these is fine)?(如何在 lucene 中索引 pdf、ppt、xl 文件(基于 java 或 python 或 php 中的任何一个都可以)?)
                KeywordAnalyzer and LowerCaseFilter/LowerCaseTokenizer(KeywordAnalyzer 和 LowerCaseFilter/LowerCaseTokenizer)
                How to search between dates (Hibernate Search)?(如何在日期之间搜索(休眠搜索)?)
                How to get positions from a document term vector in Lucene?(如何从 Lucene 中的文档术语向量中获取位置?)
                Java Lucene 4.5 how to search by case insensitive(Java Lucene 4.5如何按不区分大小写进行搜索)
              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>
                          <tbody id='634ru'></tbody>
                      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>