java - how to get file names exisiting in a folder and put it in Jtable -


when run programme, first file name repeated many times files exist in chosen folder (as rows). example, if have 3 files in folder, file1, file2 , file 3, after running programme jtable return:

file1 file1 file1 

here code:

file files = new file(directory); file[] listoffiles = files.listfiles();   defaulttablemodel dtm = new defaulttablemodel(); dtm.getdatavector().removeallelements(); dtm.firetabledatachanged(); vector datarows = new vector(); dtm.addcolumn("nom"); (file  fichier : listoffiles)  {   if (fichier.isfile())    {     filenames = fichier.getname();     if (filenames.endswith(".txt") || filenames.endswith(".txt"))     {       datarows.add(filenames);       dtm.addrow(datarows);     }   } } tblfile.setmodel(dtm); 

create new instance of vector datarows each file, otherwise you're adding names columns


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -