例:我当前xml文件内容: 1 2 3 4 5 6 //this.getFilesDir() + File.separator得到当前目录,+指定文件名,支持xml、ini、txt等 File file = new File(this.getFilesDir() + File.separator + "aaa.xml"); if (!file.exists() || file.length()== 0) { Log.d("zl","文件空"); } FileInputStream input = null; try { input = new FileInputStream(file);//得到读取流 byte[] buf = new byte[(int) file.length()]; input.read(buf); input.close(); String allParams = EncodingUtils.getString(buf, "GBK"); Log.d("zl","文件all:"+allParams); String[] paramArr = allParams.split("\n");//分割换行符 if (paramArr == null){ Log.d("zl","文件null"); } for (String param : paramArr) { Log.d("zl","logparam:"+param); } } catch (Exception e) { Log.d("zl","文件catch"); // e.printStackTrace(); }
log日志输出:
文件all:1
2
3
4
5
6