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文本文件中,都是全英文字符时,可以再控制台正常输出。
但是当文件中有中文字符时,控制台就不输出。这是怎么回事,请高手解答。
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文本文件中,都是全英文字符时,可以再控制台正常输出。
但是当文件中有中文字符时,控制台就不输出。这是怎么回事,请高手解答。
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
// 阿道夫刚帮你又测试了一下,确实没问题
1.txt的字符集又是什么?
都改成utf8试试
我刚运行了一下,没问题
Eclipse更改默认字符集 设置UTF-8
eclipse 中UTF-8设置
1.windows->Preferences 打开"首选项"对话框; 2.然后,general->Workspace,右 侧Text file encoding,选择Other,改变为UTF-8。