当前位置:操作系统 > 安卓/Android >>

[Android]向sdcard中写入文件

一,添加函数
try {
            File saveFile=new File("/sdcard/zhzhg.txt");
      
            FileOutputStream outStream = new FileOutputStream(saveFile);
            try {
                     outStream.write("文件的读写".getBytes());
                 }
            catch (IOException ex)
            {
                    Logger.getLogger(DeviceListActivity.class.getName()).log(Level.SEVERE, null, ex);
            }
            try
            {
                outStream.close();
            }
           catch (IOException ex)
          {
                Logger.getLogger(DeviceListActivity.class.getName()).log(Level.SEVERE, null, ex);
            }
     } www.zzzyk.com
    catch (FileNotFoundException ex)
    {
            Logger.getLogger(DeviceListActivity.class.getName()).log(Level.SEVERE, null, ex);
    }
二,设置向存储卡读写权限
         在AndroidMainfest.xml文件中添加:
                 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
                <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>
补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,