package My2012day02;import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;public class Csdn_Scanner { /**
 * @param args
 * @throws FileNotFoundException 
 */
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
File file = new File("c:\\1.txt");
Scanner in = new Scanner(file);
while(in.hasNextLine()){
System.out.println(in.nextLine());
} }}当1.txt文本文件中,都是全英文字符时,可以再控制台正常输出。
但是当文件中有中文字符时,控制台就不输出。这是怎么回事,请高手解答。

解决方案 »

  1.   


    public static void main(String[] args) throws FileNotFoundException {
    File file = new File("d:\\1.txt");
    Scanner in = new Scanner(file);
    while (in.hasNextLine()) {
    System.out.println(in.nextLine());
    } }
    // 打印结果
    // 哈哈哈啊哈
    // adsfsad
    // 阿道夫刚帮你又测试了一下,确实没问题
      

  2.   

    Csdn_Scanner.java的字符集什么?
    1.txt的字符集又是什么?
    都改成utf8试试
      

  3.   

    有没有报错?报错信息是什么?还有你1.txt文件里的内容都是什么???
    我刚运行了一下,没问题
      

  4.   

    看上去的确很像字符集引起的恶心错误,你可以:
    Eclipse更改默认字符集 设置UTF-8 
    eclipse 中UTF-8设置 
    1.windows->Preferences   打开"首选项"对话框; 2.然后,general->Workspace,右 侧Text file encoding,选择Other,改变为UTF-8。