I have the following code and i try to show text in text-view which in Spanish. When I run app then it showing ? at some places. Can anyone tell me detailed procedure for showing Spanish.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.information);
textview=(TextView) findViewById(R.id.information);
te开发者_如何学JAVAxtview.setText(readTxt());
}
private String readTxt(){
InputStream inputStream = getResources().openRawResource(R.raw.info);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int i;
try {
i = inputStream.read();
while (i != -1)
{
byteArrayOutputStream.write(i);
i = inputStream.read();
}
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
return byteArrayOutputStream.toString();
}
Your readTxt method is wrong.
You are returning a String representation of your ByteArrayOutputStream
and not the actual String.
Try reading the input stream into a ByteArrayInputStream
and then getting the byte array from it and on that return new String(byteArray)
;
private String readTxt(){
InputStream inputStream = getResources().openRawResource(R.raw.info);
InputStreamReader isReader = new InputStreamReader(inputStream);
BufferedReader reader = new BufferedReader(isReader);
StringBuffer buffer = new StringBuffer();
String line = null;
while ((line = reader.readLine()) != null)
{
buffer.append(line);
buffer.append("\n");
}
buffer.deleteCharAt(buffer.length() - 1); // Delete the last new line char
// TODO: Don't forget to close all streams and readers
return buffer.toString();
}
精彩评论