Hello people,
I designed this class:
package aiproject;
/*
* This class has the task to read the data stored in a file called "fichier.txt"
* line by line.
* The read lines will be put inside a List called lignesDeMonfichier
* Also, this class counts the number of lines that my file contains
* */
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class ReadMyFile{
protected List<String>lignesDeMonFichier=new ArrayList<String>();
protected int nombreDeLignesDeMonFichier;
private int n=0;
/*
* reads my file line by line
* */
public void lireFichier(){
try{
/*
* the file to be read must be named "fichier.txt"
* */
FileInputStream fistream=new FileInputStream("fichier.txt");
DataInputStream in=new DataInputStream(fistream);
BufferedReader br=new BufferedReader(new InputStreamReader(in));
String strLine;
while((strLine=br.readLine())!=null){
lignesDeMonFichier.add(strLine);
n++;
}
n=nombreDeLignesDeMonFichier;
}catch(Exception e){
System.out.println("Error: "+e.getMessage());
}
}
/*
* return the number of lines being read in my file
* */
public int getNumberOfLinesInMyFile(){
return nombreDeLignesDeMonFichier;
}
/*
* return the list of string lines being read in my file
* */
public List<String> getLinesOfMyFile(){
return lignesDeMonFichier;
}
}
Then I designed this class from which I called the method lireFichier() of the former class:
package aiproject;
/*
* This class stores after conversion the data stored in the file that has been
* read by ReadMyFile class into a 2 dimensional array of integers
* */
public class StoreFileDataIntoIntegerMatrix{
ReadMyFile readF=new ReadMyFile();
readF.lireFichier();
}
But it shows me this error with eclipse that concerns the line: readF.lireFichier():
Syntax error on token "lireFichier", Identifier expected after this token
Can you explain me what is this error and how to fix it please ?
Regards