您的位置:首页 > 移动开发 > Android开发

Android平台向SD卡写文本文件

2014-05-05 18:09 295 查看
在近来做项目的过程中需要向SD写入文本文件用于记录app的相关信息,把过程记录下来;

1.添加权限

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

2.写接口

    public void writeFileSdcard(String fileName, String message) {

      

        try { 

            FileOutputStream fout = new FileOutputStream(fileName);

            fout.write(message.getBytes());

            fout.close();

        }

 

        catch (Exception e) {

            e.printStackTrace();

        }

    }

 

使用示例

        logwrite.writeFileSdcard(Environment.getExternalStorageDirectory().getPath()+"/001.txt",

          "hello world!");

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: