文件model.obj位於我的項目的assets目錄中。出來的Toast是一個File Not Found異常。我正在我的Galaxy S3上運行該程序,而不是虛擬設備。我必須指定文件的某個路徑嗎?android FileNotFound異常
代碼:
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();
}
}
}
ManActivity:
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;
}
}