格式化和对齐PrintWriter的输出

时间:2014-09-12 04:13:55

标签: java eclipse format

如何使用PrintWriter格式化输出文件。

预期产出

09/12/2014 11:58:55   |   9999999996   |    Member - validateBp             |   VALIDATING IN REGISTRATION
09/12/2014 11:58:55   |   null         |    LoginServlet - processRequest   |   ACCESSING PAGE

当前输出

09/12/2014 11:58:55 9999999996  Member - validateBp VALIDATING IN REGISTRATION
09/12/2014 12:11:00 null    LoginServlet - processRequest   ACCESSING PAGE

谢谢!

2 个答案:

答案 0 :(得分:0)

试 使用String.format

让我们假设所有Stringid int

以外
out.println(String.format("%10s|%10d|%10s|%10s|%10s", date, id, classname.toUpperCase() ,functioname.toUpperCase() + details));

答案 1 :(得分:0)

String formattedDate = new SimpleDateFormat(" dd / MM / yyyy,HH:mm:ss")。format(date));

String Sid = Integer.toString(id);

out.println(String.format("%s |%s |%s |%s,formattedDate,Sid,classname.toUpperCase(),functioname.toUpperCase()+ details));

out.println(String.format("%10s |%10d |%10s |%10s",date,id,classname.toUpperCase(),functioname.toUpperCase()+ details));

获得4个参数。