我正在尝试从原始文件夹中检索文件内容,并使用以下代码将其显示在TextView
中,但阿拉伯字母显示为问号:
public class MalInfoFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.malinfo,
container, false);
TextView tv = (TextView) view.findViewById(R.id.malInfo);
Typeface tf = Typeface.createFromAsset(getActivity().getAssets(),"fonts/Tahoma.ttf");
tv.setTypeface(tf);
try {
InputStream IFile = getResources().openRawResource(R.raw.mal);
String strFile = inputStreamToString(IFile);
tv.setText(strFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return view;
}
public String inputStreamToString(InputStream is) throws IOException {
StringBuffer sBuffer = new StringBuffer();
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String strLine = null;
while((strLine = br.readLine()) != null){
sBuffer.append(strLine + "\n");
}
is.close();
return sBuffer.toString();
}
}