为什么在将数据从文件复制到数组 FileReader 时无法获得输出

Why I am unable to get output while copying data from file to array FileReader

我在 FileReader 上练习问题时无法获得输出 从我的角度来看,它将显示[我在哪里发布为什么没有输出特别]

import java.io.*;

public class FileWriter1 
{

    public static void main(String s[])throws Exception
    {
        //char b='a';
        File f=new File("abc.txt"); //my file has a single character a 
        f.createNewFile();

        FileReader fr=new FileReader(f);
        System.out.println(fr.read()); //1 
        char ch[]=new char[(int)(f.length())];
        fr.read(ch);//file data copied to array
        //fr.read(ch)
        for(char ch1:ch) 
        {
            System.out.println(ch1);   //2 why output is not coming here
        }
        System.out.println("********************"); //3
        FileReader fr1=new FileReader(f);
        int i=fr1.read();
        while(i!=-1)
        {
            System.out.println((char)i);  //4
            i=fr1.read();   
        }
        fr.close();
    }       
}

显示的输出:

97

*****
a

您在这里读取了文件的唯一字符:

System.out.println(fr.read()); //1 

这就是打印 97 的内容。

这就是为什么下面的阅读没有什么可读的原因:

fr.read(ch);

并且您的 ch[] 在其所有索引中仅包含默认值 char,这解释了空白输出行。