InputStream in = this.getClass().getClassLoader().getResourceAsStream("student.xml"); this报错:Cannot use this in a static context 读student.xml文件 还有其他方法吗?

解决方案 »

  1.   

    xml文件放在assets下了?你在activity里可以直接通过InputStream is = getAssets().open("student.xml");这样来获取
      

  2.   

    this.getClass()换成 类名.class
      

  3.   

    读sd卡里面的文件的方法:
    String strFilePath = Environment.getExternalStorageDirectory() + "/student.xml";
    File file = new File(strFilePath);
    InputStream is = new FileInputStream(file);
    InputStream bis = new BufferedInputStream(is);// 频繁读取文件可以用缓冲读取