• Post Reply Bookmark Topic Watch Topic
  • New Topic

read a text file  RSS feed

 
raja ramesh
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to read a text file and it can be displayed on JTable ???
 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know anything about JTable..but surely I can help you in reading a file..


Now look at the java.io package, use methods like readLine(),read() etc...

Note :
java is right handed,path will be something like this :

C:/sunny/java/
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bookmark the Java Tutorial. It has examples for many topics, like How to use Tables.
 
Rob Spoor
Sheriff
Posts: 20898
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's a CSV file you might want to check out opencsv. It works almost the same way as BufferedReader, but instead of returning a String per line it returns an array of Strings per line - one element per CSV element in the row.
 
Thiago Freitas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Raja!!
I have an example that use JTable.
if you want?
I send for you email! ok?
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Thiago.
Let's Use The Forum Not Email.
 
Thiago Freitas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forwarding an example about JTable.

code:

private void comboModeloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboModeloActionPerformed

ArrayList<Car>car;
DefaultTableModel model = (DefaultTableModel)tableCar.getModel();//tableCar is a variable of JTable
carDao = new CarDao();
car = carDao.search(String.valueOf(comboModelo.getSelectedItem()));
Object lines[] = new Object[10];

model.setRowCount(0);

for(int i = 0; i<car.size(); i++){

lines[0] = veiculo.get(i).isAvailability();
lines[1] = veiculo.get(i).getDailyValue();
lines[2] = veiculo.get(i).getMark();
lines[3] = veiculo.get(i).getModelo();
lines[4] = veiculo.get(i).getYear();
lines[5] = veiculo.get(i).getPlate();
lines[6] = veiculo.get(i).getConditions();

model.addRow(lines);

}
}
bye!!

[ January 21, 2008: Message edited by: Thiago Freitas ]
[ January 21, 2008: Message edited by: Thiago Freitas ]
 
raja ramesh
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thiago Freitas, my mail id is : [ ... ], please send me the example ..

Thanks in advance ....

[ UD: As was said above, let's use the forum, not email. Furthermore, he already posted the example. ]
[ January 22, 2008: Message edited by: Ulf Dittmer ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!