openFileOutput/openFileInput和SharedPreferances相似,都是在指定的目录下建立文件。这个目录是data/data/<packagename>/files/目录下。

使用方法如下:

                try
		{
			//  向文件写入内容
			OutputStream os = openFileOutput("file.txt", Activity.MODE_PRIVATE);
			String str1 = "abc";
			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.textview);
			textView.setText(str2);			
			is.close();
		}
		catch (Exception e) {
			
		}

通过输入输出对象流可以操作文件内的所有东西,只是这两种方法都比较局限,只能操作固定目录下的文件。