簡単な読み書き操作


public void writeFileData(String filename, String message)
{
	FileOutputStream fs = null;
	try 
	{		
		fs = openFileOutput(filename, MODE_PRIVATE);
		byte[] msg = message.getBytes();
		fs.write(msg);
	} 
	catch(FileNotFoundException e) {
		e.printStackTrace();
	}
	catch(IOException ioe)
	{
		
	}
	finally
	{
		if(fs != null)
		{
			try 
			{
				fs.close();
			} 
			catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}

public String readFileData(String filename)
{
	FileInputStream fis = null;
	String result = null;

	try 
	{
		fis = openFileInput(filename);
		int len = fis.available();
		byte[] msg = new byte[len];
		
		fis.read(msg);
		result = EncodingUtils.getString(msg, ENCODING);
	} 
	catch (FileNotFoundException e) {
		e.printStackTrace();
	} 
	catch (IOException e) {
		e.printStackTrace();
	}
	finally
	{
		if(fis != null)
		{
			try 
			{
				fis.close();
			} 
			catch (IOException e) 
			{
				e.printStackTrace();
			}
		}
	}
		
	return result;
}