读书人

Android 取.txt资料出的解方

发布时间: 2012-09-02 21:00:34 作者: rapoo

Android 取.txt文件出的解方案
其就一句:保你文件的方式和解方式一致就可以了。

如果你是取外部的文件,那接下用:

public static String encodin = "UTF8"public static String encodout = "UTF8"static void writeOutput(String str) {try {                FileOutputStream fos = new FileOutputStream("test.txt");               Writer out = new OutputStreamWriter(fos, encodout);              out.write(str);                 out.close();} catch (IOException e) {e.printStackTrace();}}static String readInput() {StringBuffer buffer = new StringBuffer();try {                       FileInputStream fis = new FileInputStream("test.txt");                  InputStreamReader isr = new InputStreamReader(fis, encodin);                       Reader in = new BufferedReader(isr);                   int ch;                 while ((ch = in.read()) > -1) {                        buffer.append((char)ch);                      }in.close();return buffer.toString();} catch (IOException e) {e.printStackTrace();return null;}}

读书人网 >Android

热点推荐