I am following some tutorial vids and learning how to read files with java. In this example the instructor creates a char array sized to 100 and then uses the FileReader class to read a text file and place the characters is the char array, and then System.out the array to the console. My code is the same as the instructor but my output includes square symbols to fill up the 100 char array, while the instructors output shows the char array correctly.
Here is the code snippet and output
import java.io.*;public class MSReader{ public static void main(String[] args) { // the character stream lasses when working // with char or strings [ reader, writer] char[] array = new char[100]; try { Reader reader = new FileReader("C:\\Users\\ricky\\OneDrive\\Desktop - Lenovo Laptop\\test\\InputStreamExample.txt"); // check if reader is ready System.out.println("Ready: " + reader.ready()); // reading the characters reader.read(array); System.out.println("Data in the stream: "); System.out.println(array); // close stream reader.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }}
Output I get:output
The instructors output doesnt show the square symbols. When I copy and paste the symbols to this site, it doesnt show up either so I had to take a screenshot of it.