gpt4 book ai didi

java - 如何将TXT文件写入SD卡?

转载 作者:行者123 更新时间:2023-12-01 04:47:05 25 4
gpt4 key购买 nike

File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File logfile = new File(path, "andrometer.txt");
String[] assignArr = new String [7];

assignArr[0]= finalValue + "17";
assignArr[1]= range + "16";
assignArr[2]= activeMode;

if (assignArr.length > 0)
{
try {
if (path.canWrite()){
FileWriter filewriter = new FileWriter(logfile);
BufferedWriter out = new BufferedWriter(filewriter);
for (int i1=0; i1<assignArr.length; i1++)
{
out.write(assignArr[0] + "\n");
out.write(assignArr[1] + "\n");
out.write(assignArr[2] + "\n");
Toast.makeText(AndroMeter.this, "out: " + assignArr[2], Toast.LENGTH_LONG).show();
}
out.close();
}
} catch (IOException e) {
Log.e("TAG", "Could not write file " + e.getMessage());
}
};

这段代码几周前还可以运行,但现在我似乎无法运行了。我相信我在 list 中拥有正确的权限,我尝试写入根目录而不是特定文件夹,我一直在使用虚拟数据代替变量名称进行测试。此时尚未创建任何文件。

最佳答案

尝试写:

FileOutputStream fo=new FileOutputStream("/sdcard/filename");

关于java - 如何将TXT文件写入SD卡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15649394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com