读取raw 文件夹下的资源
import java.io.IOException;import java.io.InputStream;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.EditText;/** * This example show how to use raw files from /raw folder * @author FaYnaSoft Labs * */public class Main extends Activity {private static String LOG_APP_TAG = "tag";private EditText editField; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); editField = (EditText) findViewById(R.id.textId); findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {InputStream inputStream = null;try {inputStream = getResources().openRawResource(R.raw.hello_world);byte[] reader = new byte;while (inputStream.read(reader) != -1) {}editField.setText(new String(reader));editField.setSelection(editField.getText().length());} catch(IOException e) {Log.e(LOG_APP_TAG, e.getMessage());} finally {if (inputStream != null) {try {inputStream.close();} catch (IOException e) {Log.e(LOG_APP_TAG, e.getMessage());}}}}}); }} InputStream inputStream = getResources().openRawResource(R.raw.rawresource);
页:
[1]