package jp.ne.biglobe.mvj.hra.helloworldsample; import java.io.File; import java.io.FileInputStream; import java.io.BufferedInputStream; import java.io.IOException; import android.app.Activity; //import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class HelloWorldSampleActivity extends Activity { /** Called when the activity is first created. */ public void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); setContentView( R.layout.main ); Button Button01 = (Button) findViewById( R.id.Button01 ); Button01.setOnClickListener( Button01ClickListener ); } /** Button01 clicked event */ private View.OnClickListener Button01ClickListener = new View.OnClickListener() { public void onClick(View v) { // SecondScreenActivity をダイアログとして表示(あとで HelloWorldSampleActivity へ戻ってくる) //Intent intent = new Intent( HelloWorldSampleActivity.this, SecondScreenActivity.class ); //startActivityForResult( intent, 0 ); try { // ファイルを buf 配列へ読み込む byte[] buf = new byte[ (int) new File( "/sdcard/test.txt" ).length() ]; BufferedInputStream f = new BufferedInputStream( new FileInputStream( "/sdcard/test.txt" ) ); f.read( buf ); f.close(); // TextView01 を取得 TextView TextView01 = (TextView) findViewById( R.id.TextView01 ); // buf配列を文字列へ変換。文字コードも変換 String s = new String( buf, "SJIS" ); // 余計な改行コードを変換 s = s.replaceAll( "\r", "" ); // TextView01 に文字列を表示 TextView01.setText( s ); } catch( IOException e ) { Toast.makeText( HelloWorldSampleActivity.this, "失敗", Toast.LENGTH_LONG ).show(); } } }; } |