我的 android File.exists 功能有一个奇怪的问题。下面是我的代码
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.fragment_file_browser, container);
DataBaseHelper tmpHelper = new DataBaseHelper(getActivity());
ButtonInfoContainer infoContainer = tmpHelper.getVideoWithId(videoId);
//Tmp way to use this. When UX is finished will create a better way.
File f = new File(Environment.getExternalStorageDirectory() + "/aslkfj");
Log.i(StaticValues.TAG, Environment.getExternalStorageDirectory() + "/aslkfj");
LinearLayout tmpView2 = (LinearLayout) view.findViewById(R.id.custom_recordings);
if(f.exists());
{
Log.i(StaticValues.TAG, "f exists");
String[] tmp = f.list();
View tmpView = null;
if(tmp != null)
{
for(int i = 0; i < tmp.length; i ++)
{
tmpView = inflater.inflate(R.layout.list_item, null);
TextView tmpText = (TextView) tmpView.findViewById(R.id.product_name);
tmpText.setText(tmp[i]);
tmpView2.addView(tmpView);
}
}
}
return view;
}
一切都很酷,但奇怪的是 File.exists 对我返回了误报。它总是说文件存在(虽然只是在这个应用程序中)。上面给出的路径 /aslkfj 不存在,但是当我运行此代码时,我的 logcat 输出 f 存在。为什么会发生这样的事情。