Java - Reading a csv file line by line - stuck with weird non-existent characters being read!

Posted by rockit on Stack Overflow See other posts from Stack Overflow or by rockit
Published on 2010-05-20T21:18:24Z Indexed on 2010/05/20 21:20 UTC
Read the original article Hit count: 224

Filed under:
|
|

hello fellow java developers. I'm having a very strange issue.

I'm trying to read a csv file line by line. Im at the point where Im just testing out the reading of the lines. ONly each time that I read a line, the line contains square characters between each character of text. I even saved the file as a txt file in wordpad and notepad with no change.

Thus I must be doing something stupid...

I have a csv file, standard csv file, yes a text file with commas in it. I try to read a line of text, but the text is all f-ed up and cannot find the phrase within the text.

Any advice? code below.

    //open csv
  File filReadMe = new File(strRoot + "data2.csv");
  BufferedReader brReadMe = new BufferedReader(new InputStreamReader(new FileInputStream(filReadMe)));

  String strLine = brReadMe.readLine();
  //for all lines
  while (strLine != null){

   //if line contains "(see also"
   if (strLine.toLowerCase().contains("(see also")){
    //write line from "(see also" to ")"
    int iBegin = strLine.toLowerCase().indexOf("(see also");
    String strTemp = strLine.substring(iBegin);
    int iLittleEnd = strTemp.indexOf(")");
    System.out.println(strLine.substring(iBegin, iBegin + iLittleEnd));
   }

   //update line
   strLine = brReadMe.readLine();
  } //end for

  brReadMe.close();

© Stack Overflow or respective owner

Related posts about java

Related posts about file