java为什么openFd(文件名)不能使用字符串?
private void startSound(String filename) throws IOException{
AssetFileDescriptor afd = getAssets().openFd(filename);
MediaPlayer player = new MediaPlayer();
player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
player.prepare();
player.start();
}
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.addForLearning:
break;
case R.id.music:
String words = mainDataTextView.getText().toString();
String con = "voice/"+words+".mp3";
try {
startSound(con);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
为什么String in openFd(filename)
不起作用?我得到了FileNotFoundException
。如果我键入openFd("voice/song.mp3")
所有的都可以,但它不适合我
# 1 楼答案
我敢打赌,你从文本视图中得到的字符串并没有删减空格
试试看
此外,如果这是不正确的,您能打印
words
包含的内容吗