Android写入文件到sd卡

  public void save() throws Exception{
        File path=Environment.getExternalStorageDirectory();
        String fileName="smsData.xml";
        File dirFile=new File(path+"/xml");
        if(!dirFile.exists())
            dirFile.mkdirs();

          FileOutputStream fos=new FileOutputStream(new File(dirFile,fileName));
          OutputStreamWriter writer=new OutputStreamWriter(fos,"UTF-8");    
          BufferedWriter w=new BufferedWriter(writer);  //缓冲区  

         w.write("测试);

        w.flush();

       w.close;

    }


加上权限:

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />





你可能感兴趣的:(Android写入文件到sd卡)