Code example for File

Methods: exists, getAbsolutePath, isDirectory

0
			builder.setTitle(getString(directoryMode ? R.string.dir_browser_title : R.string.file_browser_title)); 
			builder.setAdapter(adapter, new DialogInterface.OnClickListener() { 
				@Override 
				public void onClick(DialogInterface d, int which) { 
					chosenFile = fileList[which].file; 
					File sel = new File(path + File.separator + chosenFile); 
					if (sel.isDirectory()) { 
						firstLvl = false; 
 
						// Adds chosen directory to list 
						str.add(chosenFile); 
						fileList = null; 
						path = new File(sel.toString()); 
 
						loadFileList(); 
 
						removeDialog(DIALOG_LOAD_FILE); 
						showDialog(DIALOG_LOAD_FILE); 
					} else if (chosenFile.equals(upString) && !sel.exists()) { // Checks if 'up' was clicked 
						// present directory removed from list 
						String s = str.remove(str.size() - 1); 
 
						// path modified to exclude present directory 
						path = new File(path.toString().substring(0, 
								path.toString().lastIndexOf(s))); 
						fileList = null; 
 
						// if there are no more directories in the list, then 
						// its the first level 
						if (str.isEmpty()) { 
							firstLvl = true; 
						} 
						loadFileList(); 
 
						removeDialog(DIALOG_LOAD_FILE); 
						showDialog(DIALOG_LOAD_FILE); 
					} else { 
					    Intent result = new Intent(); 
					    if (directoryMode) { 
					        result.putExtra(RESULT_DIR_SELECTED, path.getAbsolutePath()); 
					    } else { 
					        result.putExtra(RESULT_FILE_SELECTED, sel.getAbsolutePath()); 
					    } 
					    setResult(RESULT_OK, result); 
					    removeDialog(DIALOG_LOAD_FILE); 
					    finish(); 
					}