我正在使用 python 编写自动化测试,其中 android 应用会记录音频并将其存储在特定目录中在Android设备的内部存储(sdcard0)内。
我需要检查记录(recordingX.mp3)是否确实存在于特定目录中的同名名称。如果是,则应该为最新文件指定一个新名称。
有人可以建议我为此编写一个 python测试。
答案 0 :(得分:3)
你可以试试这个
String path = getFilesDir().getAbsolutePath() + "/" + fileName;
File file = new File(path);
if(file.exists())
{
Toast.makeText(this,"file present", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(this,"file not present", Toast.LENGTH_LONG).show();
}
答案 1 :(得分:0)
使用以下行:
String path = getFilesDir().getAbsolutePath() + File.separator + "YourFileName";
File newFile = new File(path);
if (newFile.exists()) {
oldfile.renameTo("newName");
}
希望它有所帮助!