package com.example.cap10_almacenamientointernoejemplo;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;

public class AlmacenamientoInternoEjemploActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		String FILENAME = "miArchivo.txt";
		String str = "Éste es un ejemplo de alamacenamiento interno";

		FileOutputStream fos;
		try {
			fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
			fos.write(str.getBytes());
			fos.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		FileInputStream fis;
		try {
			fis = openFileInput(FILENAME);
			byte[] buffer = new byte[1024];
			StringBuilder content = new StringBuilder();
			while ((fis.read(buffer)) != -1) {
				content.append(new String(buffer));
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.almacenamiento_interno_ejemplo, menu);
		return true;
	}

}
