天空是蓝色的

做好软件为中国 #gcc -c helloworld.c -o helloworld.o //编译目标文件 #gcc helloworld.o -o helloworld //编译成可执行exe #helloworld //运行exe
数据加载中……
IO读取文件编码是utf-8的文件

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ReadFile {
       public static void main(String[] args) throws IOException{
              File file = new File("D:\\test.txt");
              FileReader fileReader = new FileReader(file);
              String sx = fileReader.getEncoding();
              FileInputStream fileInputStream = new FileInputStream(file);
              InputStreamReader inputStramReader = new InputStreamReader(fileInputStream, "utf-8");
              BufferedReader bufferedReader = new BufferedReader(inputStramReader);
              String fileContent = "";
              String line = null;
              while ((line = bufferedReader.readLine()) != null) {
                     fileContent += line + "\n";
              }
       }

}

posted on 2005-11-07 15:51 bluesky 阅读(2525) 评论(0)  编辑  收藏 所属分类: 基础知识


只有注册用户登录后才能发表评论。


网站导航: