我想在我的Android应用中阅读文件。在我的活动中,我将文件加载到列表中,然后显示所选文件的路径。但是,我需要File
对象进行下一步,这是我的代码:
public class MainActivity extends ActionBarActivity{
final StringBuffer sb = new StringBuffer();
private ListView mainListView;
private ArrayAdapter<String> listAdapter;
String filepath;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainListView = (ListView) findViewById(R.id.mainListView);
final ArrayList<String> List = new ArrayList<String>();
final File storage = Environment.getExternalStorageDirectory();
final File file = new File(storage, "/Folder/");
if(file.exists() && file.isDirectory()){
for (String s : file.list()){
sb.append(s + " ");
List.addAll(Arrays.asList(s));
}
}
listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow, R.id.rowTextView,List);
mainListView.setAdapter(listAdapter);
mainListView.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3){
String filepath = new File("/Folder/"+ List.get(arg2)).getAbsolutePath();
}
});
}
我该如何解决这个问题?下一个方法有输入(文件文件)