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());
}
};
这段代码在几周前就开始工作了,现在我似乎无法理解。我有正确的清单中的权限我相信,我尝试写入root而不是特定的文件夹,我一直在用虚拟数据代替变量名进行测试。此时没有创建文件。
答案 0 :(得分:0)
尝试写作:
FileOutputStream fo=new FileOutputStream("/sdcard/filename");