0

After importing a CSV file and sorting it in to a 2-Dimensional array I get a couple of weird characters in only the first and possibly the last cell.

Expected output: S1358_R1

Actual output: S1358_R1

Does anyone know why these extra characters show up? The code used to do this is included below:

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class open2 {
    public static void main(String[] args) {
        String line = "";
        String splitBy = ",";
        try {
            //parsing a CSV file into BufferedReader class constructor
            int i = 0;
            String[][] ss = new String[10000][10000];
            BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\micha\\Documents\\spreadsheet.csv"));
            while ((line = br.readLine()) != null) //returns a Boolean value  
            {

                String[] cells = line.split(splitBy);
                for (int j = 0; j < cells.length; j++) {
                    ss[i][j] = cells[j];

                } // use comma as separator  
                i = i + 1;
            }

            System.out.println(ss[0][0]);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
andrewJames
  • 19,570
  • 8
  • 19
  • 51
  • 1
    Does this answer your question? [What's  sign at the beginning of my source file?](https://stackoverflow.com/questions/18845976/whats-%c3%af-sign-at-the-beginning-of-my-source-file). In other words, that is a BOM (a byte order mark). – andrewJames Sep 22 '22 at 23:57
  • 1
    Also related: [Byte order mark screws up file reading in Java](https://stackoverflow.com/q/1835430/12567365). The best approach is probably to try to prevent that from being added to the source file in the first place (for example, by avoiding use of Notepad). But we cannot be sure without knowing how it got there in the first place. – andrewJames Sep 22 '22 at 23:59

0 Answers0