Good all;
I am trying to read some files (from assets) based upon list selections. The code below opens the file and retrieves the content nicely even Arabic letters. the only problem is that the text comes as a very long string without any spaces or newlines. for example the file content is:
first line
second line
third line
the output will be : firstlinesecondlinethirdline
the code is :
public void onItemSelected(AdapterView parent, View v,
int position, long id) {
String filename = getFileName(position);
InputStreamReader ls = null;
try {
AssetManager am = getResources().getAssets();
ls = new InputStreamReader(am.open(filename), "UTF-8");
StringBuffer sb = new StringBuffer();
while( true ) {
int c = ls.read();
if( c < 0 )
break;
if( c >= 32 )
sb.append( (char)c );
selection.setText(new String(sb));
}
} catch(IOException e) {
Log.e(LOG_APP_TAG, e.getMessage());
} finally {
if (ls != null) {
try {
ls.close();
} catch (IOException e) {
Log.e(LOG_APP_TAG, e.getMessage());
}
}
}
}
New line has character value of 10 (<32), so its not appended, so consider appending all characters with >0 value, hence change to