0

我尝试了下面的代码,如果我重命名音乐文件Musik_stk100.mp3,如果仍然返回 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);
    }
4

0 回答 0