JTable reading text files from second line

后端 未结 1 1464
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-22 11:37

I\'m working on JTable that reads text from a .txt file. the txt file gets updated dynamically after 3 sec. Now when I run the application, everything is good except that th

相关标签:
1条回答
  • 2020-12-22 12:10

    I'd do this a little differently, avoiding an intermediate text file. Instead,

    • Use ProcessBuilder, which "can be invoked repeatedly from the same instance." You can read the output as shown here and parse it into a suitable data structure, e.g. List<List<String>>.

      ProcessBuilder pb = new ProcessBuilder("ps -ef");
      
    • Start a javax.swing.Timer having a three second period; invoke pb.start() in the timer's listener.

    • When parsing concludes, fireTableDataChanged() in your AbstractTableModel, shown here.

    Presto, your table updates with the latest result every three seconds.

    0 讨论(0)
提交回复
热议问题