Hi all,
i'm trying to get a specific line in a text from a text file.
In fact i want to read just the eight first line from my text file.
It's only return the four first line. why?
here is my code but, there is Format problem.
import java.io.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class ReadLine
{
public static void main(String[] args)
{
//String chaine = null;
// read the file
try {
InputStream ips = new FileInputStream("File.txt");
InputStreamReader ipsr = new InputStreamReader(ips);
BufferedReader br = new BufferedReader(ipsr);
String ligne;
int numLigne =0;
int nombreDeLignes =8;
int[] var = new int[nombreDeLignes ];
while ((ligne = br.readLine()) != null)
{
numLigne++;
System.out.println(ligne);
//chaine += ligne + "\n";
int ind = ligne.indexOf(" ");
var[numLigne -1] = Integer.parseInt(ligne.substring(0, ind));
}
for (int i = 0; i < var.length; i++)
{
System.out.println("var[" + i + "] = " + var[i]);
}
br.close();
}
catch (Exception e)
{
System.out.println(e.toString());
}