-1

I am trying to read the character: " from BufferedReader onto a string. However, it displays the quote character as a square box.

            //Opens file
            File file = fc.getSelectedFile();
            //filePath
            String filePath = file.getPath();

            //Holds a line of text from the file
            String line = null;

            try
            {
                //Reads text from file
                FileReader fileReader = new FileReader(filePath);
                BufferedReader bufferedReader = new BufferedReader(fileReader);

                //Reads each line onto the left text area (encryptMessageTA)
                while ((line = bufferedReader.readLine()) != null)
                {
                    System.out.println(line);
                }
            }
            //File not found
            catch (FileNotFoundException ex)
            {
                System.out.println(ex.getMessage()); //prints exception
            } 
            //Input/Output exception
            catch (IOException ex)
            {
                System.out.println(ex.getMessage()); //prints exception
            }
Tommy Saechao
  • 1,099
  • 4
  • 17
  • 28

1 Answers1

-1

This is not a problem with the BufferedReader. It may be a problem with the FileReader or with where System.out prints, because it's a code page problem.

When FileReader is reading the file, it's reading in the default code page, usually Windows-1252 if you're using Windows in the US.

The real problem is that your file contains non-ASCII quotation marks. Unicode has a lot of different quotation marks. See here for list. The most common ones are:

If your file contains any of the last two, and your console cannot display those, you'll see boxes, which represent failed mappings of characters.

Andreas
  • 154,647
  • 11
  • 152
  • 247