I have a particular file that Java says is empty…
Source Code
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class MinimumWorkingExample
{
public static void main(String[] args) throws FileNotFoundException
{
String filename = "/home/tyson/Data/English-French_test/test/test.f";
Scanner fileIn = new Scanner(new File(filename));
System.out.println("***START***");
while(fileIn.hasNextLine())
{
System.out.println(fileIn.nextLine());
}
System.out.println("***FINISH***");
}
}
Output
***START***
***FINISH***
…but the file is not empty:
Console
tyson@tyson-desktop:~$ head /home/tyson/Data/English-French_test/test/test.f
<s snum=0001> 2 . </s>
<s snum=0002> 2 . </s>
<s snum=0003> oh , oh ! </s>
<s snum=0004> oh , oh ! </s>
<s snum=0005> oh , oh ! </s>
<s snum=0006> souvenons - nous , monsieur le Orateur , que ce sont ces secteurs de notre soci�t� qui servent de �pine dorsale � notre �conomie . </s>
<s snum=0007> bravo ! </s>
<s snum=0008> bravo ! </s>
<s snum=0009> monsieur le Orateur , ma question se adresse � le ministre charg� de les transports . </s>
<s snum=0010> tous deux poss�dent de nombreuses ann�es de exp�rience dans la fabrication et la distribution de les produits forestiers . </s>
tyson@tyson-desktop:~$
Question
Why is this happening???
Also do Scanner fileIn = new Scanner(new File(filename), “Cp1252”); as this is the encoding for French, and your system seems to be UTF-8.
The Scanner might have encoding problems if it thinks to read UTF-8 multibytes.