Java读取txt


FileReader fr=new FileReader("D:\\workspace\\MyLearn\\count.txt");
        //可以换成工程目录下的其他文本文件
        BufferedReader br=new BufferedReader(fr);
        while(br.readLine()!=null){
            String s=br.readLine();
            System.out.println(s);
        }
用readLine后

s最后会变空


public static void main(String[] args) throws Exception
    {
        File file = new File("d:\\a.txt");
        FileReader reader = new FileReader(file);
        int fileLen = (int)file.length();
        char[] chars = new char[fileLen];
        reader.read(chars);
        String txt = String.valueOf(chars);
        System.out.println(txt);
    }

txt不会

猜你喜欢

转载自blog.csdn.net/xiaofeng3011/article/details/74514596
今日推荐