1
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());
    }
};

这段代码几周前还在工作,现在我似乎无法做到。我相信我在清单中拥有正确的权限,我尝试写入根目录而不是特定文件夹,我一直在用虚拟数据代替变量名进行测试。此时没有创建文件。

4

1 回答 1

0

试着写:

FileOutputStream fo=new FileOutputStream("/sdcard/filename");
于 2013-03-27T02:49:56.700 回答