文件 model.obj 位于我项目的 assets 目录中。出来的吐司是 File Not Found 异常。我在我的 Galaxy S3 上运行该程序,而不是虚拟设备。我必须指定文件的一些路径吗?
代码:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import android.content.Context;
import android.app.Activity;
public class ImportOBJ {
protected void onCreate(String filename,Context context)
{
try
{
FileInputStream fis = context.openFileInput(filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
String line = null, input="";
while( (line = reader.readLine()) != null )
{
input += line;
}
reader.close();
fis.close();
}
catch (Exception ex)
{
Toast.makeText(context, ex.toString(), Toast.LENGTH_LONG).show();
}
}
}
人活动:
package com.example.tictactoeshowgrid;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ImportOBJ obj_import=new ImportOBJ();
obj_import.onCreate("model.obj",MainActivity.this);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}