FileReader reader = new FileReader(new File(r.readLine())); FileReader reader = new FileReader(r.readLine()); 

Is there a difference between the name declarations for the streams and what new File () gives us. Or does it register itself if it isn’t written?

    2 answers 2

    There is no difference, because If you look at the constructor where the string is transmitted, you will see the following:

     public FileReader(String fileName) throws FileNotFoundException { super(new FileInputStream(fileName)); } public FileInputStream(String name) throws FileNotFoundException { this(name != null ? new File(name) : null); } 

    And here, where the file

     public FileReader(File file) throws FileNotFoundException { super(new FileInputStream(file)); } 

    As you can see, in both cases the same constructor is called on the FileInputStream

      Apparently (for example, if r is an instance of BufferedReader ), these are different constructors : in the first case, this is a constructor

       FileReader(File file) 

      and in the second

       FileReader(String fileName) 

      In both cases, a new FileReader is created, but in the first constructor, the File specified as a parameter, and the second specifies the file name as a string.