无法正确对齐输出

Not able to get output properly aligned

  1. 列表项

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStreamReader;
    public class test104 {
        public String[] b=new String[200];
        public String flex(String ps) throws IOException
        {   
            String result="";
            File file=new File("C:\ProgramData");
    
            ProcessBuilder pb = new ProcessBuilder("cmd","/C",ps);
    
    
            pb.directory(file);
    
            Process p = pb.start();
    
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    p.getInputStream()));
            String readline;
            //result=reader.readLine();
            int i=0;
            result=reader.readLine();
            StringBuilder sb = new StringBuilder();
            while ((readline = reader.readLine()) != null) {
                sb.append(readline);
                System.out.println(readline);
                b[i]=readline;
                i++;
                System.out.println("<br>");
            }
    
            try {
            int exitValue = p.waitFor();
            } 
    
            catch (InterruptedException e) {
            e.printStackTrace();
            }
    
    
            finally{
            //out.close();  
            } 
    
            return sb.toString();
        }}
    
        Print.jsp
    
        </head>
        <%@ page import="com.test104" %>
        <body>
        <% 
         com.test104 f1=new test104();
         int j=0;
         String k=f1.flex("dir");
         String readline;
         out.println(k);
    
         %>
    

输出未对齐直线。它应该一个接一个地出现。!

Here 是 jsp 页面中的输出。

沿

行的代码
 StringBuilder sb = new StringBuilder();
 while ((readline = reader.readLine()) != null) {
     sb.append(readline);
 }
 someOutputMethod( sb.toString() );

将从 reader 读取的输入中删除所有行尾。您必须在每行之后或您认为有必要时附加行尾 '\n'