0

Relate from my first question at Execute linux command in java and display output to html table I have manage to get it work, but I still have one other question: how I can remove the first line from the output? Below is the code:

<%
String[] disk;
String line;
String process;
Process p;
BufferedReader input;
p = Runtime.getRuntime().exec("df -h");
input = new BufferedReader(new InputStreamReader(p.getInputStream()));
%>
        <tr bgcolor="#f0f0f0">
            <td>
                <b>Disk</b>
            </td>
            <td>
                <b>Size</b>
            </td>
            <td>
                <b>Used</b>
            </td>
            <td>
                <b>Avail</b>
            </td>
            <td>
                <b>Use %</b>
            </td>
            <td>
                <b>Mounted</b>
            </td>
            <td>
            </td>
        </tr>
<%
    while ((line = input.readLine()) != null)
    {
    disk = line.split("\\s+");
%>
        <tr>
        <td><% out.println(disk[0]); %></td>
        <td><% out.println(disk[1]); %></td>
        <td><% out.println(disk[2]); %></td>
        <td><% out.println(disk[3]); %></td>
        <td><% out.println(disk[4]); %></td>
        <td><% out.println(disk[5]); %></td>
        </tr>
<%
    }
    input.close();
%>

The output is like:

Here

What I want to remove is Filesystem Size Used Avail Use% Mounted that showing after table header.

Community
  • 1
  • 1
hrace009
  • 37
  • 9

2 Answers2

2

Read 1 line before the while loop, by adding this line before the loop:

input.readLine();
Bohemian
  • 412,405
  • 93
  • 575
  • 722
-1

Skip the first line?

 int count = 0;
 while ((line = input.readLine()) != null)
    {
      count++;
      if (count == 1) continue; 

    disk = line.split("\\s+");
Alexey Soshin
  • 16,718
  • 2
  • 31
  • 40