用阿拉伯语阅读文件内容

时间:2014-06-23 08:53:48

标签: android textview arabic

我正在尝试从原始文件夹中检索文件内容,并使用以下代码将其显示在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();
    }
}

0 个答案:

没有答案