I have a .txt file that has a text on it, and i want to read from it and show it on a JTextField but I dont know how to code it.

So far here's what i know:

viewIO = new DataInputStream(new FileInputStream(phoneList.getModel().getElementAt(phoneList.getSelectedIndex())+".dat"));
for(int x = 0; x < 5; x++)
{
    field[x].setText(viewIO.readUTF());
}

is this code will work? nothing appears on the JTextField as the program runs

Recommended Answers

All 3 Replies

please help...

we know nothing from the names of your components, input fields, ... how do you expect us to be of much help.

The complex statement on line 1 could be going wrong in a number of places. Break it up into separate statements and print the result at each step to confirm what it is really doing. Similarly, print the results of the readUTF to confirm exactly what that is doing.
You talk about a textfield, but the code implies that you have at least 5 text fields. That's confusing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.