Android过程:InputStream-InputStremRreader-BufferedReader-String;其中 InputStream inputStream=getResources().openRawResource(R.raw.abc);//abc 为 在res/raw文件下的txt文件Java读取外部txt文件InputStreamReader read =
new
InputStreamReader(
new
FileInputStream(file),encoding);
//考虑到编码格式
public String getString( InputStream inputStream) { InputStreamReader inputStreamReader = null; try { inputStreamReader = new InputStreamReader(inputStream, "gbk"); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } BufferedReader reader = new BufferedReader(inputStreamReader); StringBuffer sb = new StringBuffer(""); String line; try { while ((line = reader.readLine()) != null) { sb.append(line); } } catch (IOException e) { e.printStackTrace(); } sb.close; return sb.toString();}
时间: 2024-11-07 16:13:35