: first thanks ... What I understood is that u r suggesting to print each part of the record into a separate JTextField : However, I want to Print each line in the file in one TextField with each line being one record: Now I think that we may use the code that I presented previously:
:
: String S, name;
: String S2="";
: name=jTextField1.getText().trim();
: try{
: BufferedReader in = new BufferedReader ( new FileReader(name));
: int i=0;
: while ((S=in.readLine())!=null)
: {
: i++;
: S2+=S+"\t\t";
: if (i%3==0)
: S2+="\n";
: }
: in.close();
: } catch (IOException e) {
: JOptionPane.showMessageDialog(this,"File NOT Found");
: }
: jTextArea1.setText(S2);
:
:
: then each line will be stored in S and the whole file will be stored in S2 string. Is that right?????
:
: i dont know maybe there is the pblem of differentiating the different parts of eachh record(ex differentiating between the name and ID....)then i should think of transforming the string S into the object Student (for e.g.) ....
:
: please any suggestions?? And if am understanding things in a wrong way plz help me and correct me !
:
: thanks a lot
:
:
I would use methods in the Student class, which does the reading and writing. For example:
void readFromFile(BufferedReader f) {
String[] fields = f.readLine().split('/t');
if (fields.length == numberOfFields) {
name = fields[0];
id = Integer.parseInt(fields[1]);
}
}
void writeToFile(BufferedWriter f) {
String s =
name + '/t' +
Integer.toString(id) + '/t' +
}
This code uses the tab character to differentiate between the various fields. If tab may be used in one of the fields, then you should use another character, such as the character #1 or #2, since these are not typable.