【问题标题】:Creating a textfile and saving it to a particular location in android phone创建文本文件并将其保存到 android 手机中的特定位置
【发布时间】:2011-06-22 22:11:14
【问题描述】:

我想创建一个从蓝牙接收到的数据的文本文件,然后将其保存到另一个应用程序可以使用的位置。

如何使用代码解决这个问题?

【问题讨论】:

  • 请发表你所做的。

标签: android file copying


【解决方案1】:

使用FileWriter 是最简单的方法之一:

File dir = Environment.getExternalStorageDirectory();
FileWriter writer = new FileWriter(new File(dir, "name.txt"));
writer.append("Hola\n");
writer.append("Hello\n");
writer.append("Etc...\n");
writer.flush();
writer.close();

这会将文件保存到 SDCard 目录,其他应用程序可以访问该目录。确保在您的清单文件中包含WRITE_EXTERNAL_STORAGE 权限。

【讨论】:

  • 我不想复制到 sdcard 目录,而是复制到手机内存中其他应用程序可以访问的其他目录
  • 其他应用程序无法访问其他目录 ;)
  • 我想将文件复制到保管箱文件夹,那么代码应该是什么。
  • 是的,您可以在 SDCard 内创建另一个目录。有很多关于如何做到这一点的教程:)
【解决方案2】:

看起来像欺骗/与StackOverflow: Saving file to phone in stead of SD-card有关

您应该能够使用常规 java File IO 类将实际数据保存到文件中。

【讨论】:

    猜你喜欢
    • 2016-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-19
    • 2020-10-10
    相关资源
    最近更新 更多