1 Attachment(s)
[SOLVED] Help with JTextFile display
Hi all,
I am new to this forum and this is my first post: I am a Java beginner and I hope to have some help from you.
I have a method that reads and return how many rows there are in a txt file, and it works fine.
Code:
public int numberOfLines(){
lines = 0;
if(checkIsFile()){
try{
FileReader fr = new FileReader(fileToImport);
BufferedReader br = new BufferedReader(fr);
while((br.readLine()!=null)){
lines++;
}//end while loop
br.close();
}catch(Exception e){
System.out.println(e);
}
}
else{
System.out.println("There is no file to import");
}
return lines;
}
I would like to have this returned number (total rows in file) into a JTextField, as the attached picture: how should I modify my method?
Thanks!
Susanna Ferrari