/*
Simple program...
Runs fine no errors.
Problem, the file has 1440 records of text lines. The program will only read around 400 lines.
The number of records read vary with each run.
I have tried other examples but all have the same problem.
Can anyone solve this ????
/**
*
* @author ubuntu
*/
import java.io.*;
import java.util.Scanner;
public class Test {
public static void main(String [] args) {
//String fileName="/home/ubunbtu/NetBeansProjects/CiSentances/src/cisentances/sentences.txt";
String fileName = "/home/ubuntu/NetBeansProjects/CiSentances/src/cisentances/sentences.txt";
// The name of the file to open.
// This will reference one line at a time
String line = null;
int count=0;
try {
FileInputStream inputStream = new FileInputStream(fileName);
Scanner sc = new Scanner(inputStream, "UTF-8");
while (sc.hasNextLine()) {
line = sc.nextLine();
/* // FileReader reads text files in the default encoding.
FileReader fileReader =
new FileReader(fileName);
// Always wrap FileReader in BufferedReader.
BufferedReader bufferedReader =
new BufferedReader(fileReader);
while((line = bufferedReader.readLine()) != null) {
*/
count++;
System.out.println(count + " " + line);
}
// Always close files.
// bufferedReader.close();
}
catch(FileNotFoundException ex) {
System.out.println(
"Unable to open file '" +
fileName + "'");
}
catch(IOException ex) {
System.out.println(
"Error reading file '"
+ fileName + "'");
// Or we could just do this:
// ex.printStackTrace();
}
}
}