• Post Reply Bookmark Topic Watch Topic
  • New Topic

Populating a JTable from a text file  RSS feed

 
Stacy Eleuterius
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to populate a JTable with data from a text file. In the text file, the fields are separated by tabs (but could be separated by commas, spaces, etc). How is this done.
Thanks for your help, I am a Java rookie!!!
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stacy,

what u can do is like this.
1) read a line from the file using BufferedReader
2) Tokenize this line using StringTokenizer by default StringTokenizer will separate tokens on the basis of tab and space character.
3)Now you consider each token one by one and check if it contains
a , ( comma ) . in case it contains comma then you further tokenize this token using , as delimiter and so on. untill you reach the actual field.
4) keep on adding the final token to a Vector
5) and pass this Vector to JTable Constructor.
regards
Deekasha

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!