Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to read text file?

807580Oct 26 2009 — edited Oct 26 2009
Dear Everyone
I have coding below.
{color:#3366ff}*Text file scores.txt*
{color}1 1 1
2 2 2
*{color:#3366ff}Java class jtableone.class{color}*
import javax.swing.*;
public class jtableone extends JApplet {
public static void main(String[] args) throws Exception {
{color:#ff0000}//Read file scores.txt{color}
java.io.File file = new java.io.File("scores.txt");
Scanner input = new Scanner(file);
while (input.hasNext()){
String id = input.next();
String firstname = input.next();
String lastname = input.next();
{color:#ff0000}//System.out.println(id +" "+ firstname +" "+ lastname);
{color}}
input.close();
}
{color:#ff0000}//Crearte JTable{color}
private String[] columNames =
{"ID", "First Name", "Last Name"};

private Object[][] data = {
//{"12", "Tom", "Clark"},
//{"13", "helen", "Tan"}

};
{color:#ff0000}//Display JTable{color}
private JTable jTable1 = new JTable(data, columNames);
public jtableone(){
add(new JScrollPane(jTable1));
}
}
Can you tell me What i do next?
Create a Object[][] data which can read text file.
Thanks
sevenlon
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 23 2009
Added on Oct 26 2009
4 comments
219 views