javafx - Java FX - Data FX - Loading a CSV file into a TableView -
i'm trying load content of csv file tableview using datafx. i've created new javafx project, nothing loading file in background. in controller, have following code
file file = new file("test.csv");             if (file.exists() && file.canread()) {                 datasourcereader dsr1 = new filesource(file);                   string[] cols ={"fname","lname","address"};                 mycsvdatasource ds1 = new mycsvdatasource(dsr1, cols);                 tableview tableview = new tableview();                 tableview.setitems(ds1.getdata());                  system.out.println("csv : " + ds1.getdata().size()); ds1.getdata().size() returns zero. i've taken care of spaces, column names, etc. csv extremely simple , i've wrote notepad++:
fname,lname,address frank,noris,42 iopus drive ann,coleman,po box 12345 thomas,test,1 bills drive since not figure problem, i've downloaded source code of csvdatasource.java , datasource.java , used instead, can set println , use debugger analyse. in background, csvdatasource creates inner class , service, uses load contents of file. i've added println within task execution function:
@override protected task createtask() {     task task = new task() {          @override         protected object call() throws exception {             try {                 bufferedreader br = new bufferedreader(new inputstreamreader(myreader.getinputstream(), "utf-8"));                 string line;                 int row = 0;                 while ((line = br.readline()) != null) {                     system.out.println(line);                     if (line.trim().isempty()) {                         continue;                     } executing output following:
csv : 0 fname,lname,address frank,noris,42 iopus drive ann,coleman,po box 12345 thomas,test,1 bills drive with understand service executed after call ds1.getdata().size() although start called in csvdatasource constuctor:
public mycsvdatasource(datasourcereader reader, string... cols) {     (string col : cols) {         selectedcolumnnames.add(col);     }     dataretriever retriever = new dataretriever(reader);     retriever.start();         } so 0 @ moment ds1.getdata().size() called. can please confirm if assupmtion correct , how load csv. fyi, moved code application file, , problem persists.
thank in advance.
 
 
Comments
Post a Comment