我有一個particular file是Java的說是空的...Java說一個非空文件是空的?
源代碼
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***");
}
}
輸出
***START***
***FINISH***
...但該文件不爲空:
控制檯
[email protected]:~$ 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>
[email protected]:~$
問題
這究竟是爲什麼???
我試着用附加文件的程序,我能夠正確讀取文件的內容。 – 2011-12-22 02:25:06
@Jugal Joop建議,由於文件是法文的,我應該使用'Scanner fileIn = new Scanner(新文件(文件名),「Cp1252」);'正確讀取文件。此修補程序適用於我。出於好奇,知道爲什麼你的系統默認可以正確閱讀法文(但我的不能)? – 2011-12-22 02:33:11