我是初学者,我想问为什么这段代码不起作用?
我正在尝试实现如何在assets子目录中的选项中打开* .txt文件。
mTopicOneList = new ArrayList(Arrays.asList(getResources().getStringArray(R.array.topic_one)));
ListView list = (ListView) findViewById(R.id.topic_one_list);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view,
int position, long id) {
intent = new Intent(view.getContext(), TextActivity.class);
AssetManager assetManager = getApplicationContext().getAssets();
InputStream input;
String assetsString;
try {
String[] subDirectoryFileList = assetManager.list("topicone/");
input = assetManager.open(subDirectoryFileList[position]);
int size = input.available();
byte[] buffer = new byte[size];
input.read(buffer);
input.close();
assetsString = new String(buffer);
intent.putExtra("textFromAssets",assetsString);
} catch (IOException e) {
e.printStackTrace();
}
startActivity(intent);
}
});