我尝试了下面的代码,如果我重命名音乐文件Musik_stk100.mp3
,if仍然会返回true?
我做错了什么?
String filepath = "file:///mnt/sdcard/data/musikapp/";
final File musicfile = new File(filepath + "/" + "Musik_stk100.mp3");
final ImageView imagetrue = (ImageView) findViewById(R.id.imagetrue);
final ImageView imagefalse = (ImageView) findViewById(R.id.imagefalse);
if (musicfile.exists()){
imagetrue .setVisibility(View.VISIBLE);
imagefalse .setVisibility(View.GONE);
} else {
imagefalse .setVisibility(View.VISIBLE);
imagetrue .setVisibility(View.GONE);
}
解
String filepath = (Environment.getExternalStorageDirectory() + "/data/musikapp/");
final File musicfile = new File(filepath + "Musik_stk100.mp3");
final ImageView imagetrue = (ImageView) findViewById(R.id.imagetrue);
final ImageView imagefalse = (ImageView) findViewById(R.id.imagefalse);
if (musicfile.exists()){
imagetrue .setVisibility(View.VISIBLE);
imagefalse .setVisibility(View.GONE);
} else {
imagefalse .setVisibility(View.VISIBLE);
imagetrue .setVisibility(View.GONE);
}