Additional spaces in String having read text file to String using FileInputStream

Posted by David on Stack Overflow See other posts from Stack Overflow or by David
Published on 2010-05-08T00:13:02Z Indexed on 2010/05/08 0:18 UTC
Read the original article Hit count: 652

Filed under:
|
|
|

Hi, I'm trying to read in a text file to a String variable. The text file has multiple lines. Having printed the String to test the "read-in" code, there is an additional space between every character. As I am using the String to generate character bigrams, the spaces are making the sample text useless. The code is

try{ FileInputStream fstream = new FileInputStream(textfile);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));

//Read corpus file line-by-line, concatenating each line to the String "corpus"
while ((strLine = br.readLine()) != null)   
 {
  corpus = (corpus.concat(strLine));    
 }

in.close();    //Close the input stream  

} catch (Exception e) {//Catch exception if any System.err.println("Error test check: " + e.getMessage()); }

I'd be grateful for any advice.

Thanks.

© Stack Overflow or respective owner

Related posts about spaces

Related posts about read