android写文件到存储中,如何在android上的外部存储上写文件到文件?

将一些文本写入Android设备上的文件似乎是一项重大努力.从这里给出的答案开始,我已将以下代码实现到我的单个"Hello-World"活动中:

try {

OutputStreamWriter outputStreamWriter = new OutputStreamWriter(this.openFileOutput("config.txt", Context.MODE_PRIVATE));

outputStreamWriter.write("lalala");

outputStreamWriter.close();

} catch (IOException e) {

Log.e("Exception", "File write failed: " + e.toString());

}

这不会引发异常,但似乎有效.但有没有办法"看到"使用File Manageron android 创建的文件?代码片段似乎写入android文件系统上与应用程序本身相关的"秘密"位置(由using控制this.openFileOutput).

咨询不同的谷歌链接(这个 和这个 和这个)我想出以下代码:

File file = new File(this.getExternalFilesDir("temp"), "testfile.txt");

FileOutputStream fileOutput = openFileOutput(file.getName(), Context.MODE_WORLD_WRITEABLE);

fileOutput.write("lalala");

fileOutput.close();

这会引发错误

Error:(55, 19) error: no suitable method found for write(String) method FileOutputStream.write(int) is not applicable (actual argument String cannot be converted to int by method invocation conversion) method FileOutputStream.write(byte[],int,int) is not applicable (actual and formal argument lists differ in length) method OutputStream.write(int) is not applicable (actual argument String cannot be converted to int by method invocation conversion) method OutputStream.write(byte[],int,int) is not applicable (actual and formal argument lists differ in length) method OutputStream.write(byte[]) is not applicable (actual argument String cannot be converted to byte[] by method invocation conversion)

那么怎么做呢?

作为旁注:这仅用于调试/教育目的,并非旨在成为最终应用程序的一部分!

需要明确的是:我想创建中的文件temp目录,我可以用文件管理器看到(该temp目录是在同一水平My Documents

,Music,DCIM,Download等...)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值