Java 使用Formatter.format时如何输出新行?

Java 使用Formatter.format时如何输出新行?,java,Java,在这个程序中,我所有的东西都运行得很好,但是在addRecord()函数中,我需要添加更多的信息,但我无法将其打印在新行上。所有的东西都显示在同一行中。有人能指出这一点吗 谢谢。使用%n格式说明符通过格式化程序#format(…)添加新行。因此,请将其添加到格式字符串的末尾。尝试在格式中使用%n',或在换行时使用\n`。@bmthaker:\n在格式化程序中不受欢迎。你应该只使用%n。得到输出的人..谢谢你的支持..你能详细解释..用一个合适的例子..我已经尝试了上面提到的方法…可能是我搞砸了.

在这个程序中,我所有的东西都运行得很好,但是在addRecord()函数中,我需要添加更多的信息,但我无法将其打印在新行上。所有的东西都显示在同一行中。有人能指出这一点吗
谢谢。

使用
%n
格式说明符通过
格式化程序#format(…)
添加新行。因此,请将其添加到格式字符串的末尾。

尝试在格式中使用
%n',或在换行时使用
\n`。@bmthaker:
\n
在格式化程序中不受欢迎。你应该只使用
%n
。得到输出的人..谢谢你的支持..你能详细解释..用一个合适的例子..我已经尝试了上面提到的方法…可能是我搞砸了..请你给我一个简短的例子。@chaoabishekpukan:哦,看在皮特的份上,在
格式(…)
调用中,只需将
%n
放在格式字符串的末尾。来吧,你当然可以试着这么做。好的,好的,我现在有输出了…呵呵…thanx a Ton继续帮助…我们是学习者。。。
import java.io.*;
import java.lang.*;
import java.util.*;

public class createfile {
    public static void main(String args[]){

        createfile obj= new createfile();
        obj.openfile();
        obj.addRecords();
        obj.closefile();
        System.out.println("You have created a file");

    }
    private Formatter x;
    public void openfile(){

        try{
            x = new Formatter("C:\\test\\chinese.txt");
        }
        catch(Exception e){
            System.out.println("You have an error");
        }
    }




    public void `addRecords`(){
        x.format("%s %s %s","21","alex","software programmer");
        x.format("%s %s %s","22","greg", "architecture");
    }
    public void closefile(){
        x.close();
    }
}