1 package min.conquer;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.FileOutputStream;
6 import java.io.IOException;
7
8 import org.apache.http.util.EncodingUtils;
9
10 import android.app.Activity;
11 import android.os.Bundle;
12 import android.util.Log;
13 import android.widget.TextView;
14
15 public class IoActivity extends Activity {
16 private FileInputStream in;
17 private FileOutputStream out;
18 private File file;
19 final String TAG = "嘿嘿写入文件了";
20 String display;
21 String PATH = "/data/data/min.conquer";
22 String NAME = "kk.txt";
23 /** Called when the activity is first created. */
24 @Override
25 public void onCreate(Bundle savedInstanceState) {
26 super.onCreate(savedInstanceState);
27 file = new File(PATH , NAME);
28 try{
29 file.createNewFile();
30
31 out = new FileOutputStream(file);
32 out.write(TAG.getBytes());
33
34 int length = (int)file.length();
35 byte[] temp = new byte[length];
36 in = new FileInputStream(file);
37 in.read(temp, 0, length);
38
39 display = EncodingUtils.getString(temp, "UTF-8");
40 in.close();
41 }catch(IOException e){
42 Log.e(TAG, e.toString());
43 }
44
45 TextView tv = new TextView(this);
46 tv.setText(display);
47 setContentView(tv);
48 }
49 }