文件存储

public class FileOutput extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		try
		{
			OutputStream os = openFileOutput("file.txt", Activity.MODE_PRIVATE);
			String str1 = "《Android/OPhone开发完全讲义》";
			os.write(str1.getBytes("utf-8"));
			os.close();

			InputStream is = openFileInput("file.txt");
			byte[] buffer = new byte[100];
			int byteCount = is.read(buffer);
			String str2 = new String(buffer, 0, byteCount, "utf-8");
			TextView textView = (TextView)findViewById(R.id.tv01);
			textView.setText(str2);			
			is.close();
		}
		catch (Exception e) {
			
		}
	}
 
}

 

你可能感兴趣的:(文件)