android文件存取

写的方法:

private void write(String content){
		try {
			FileOutputStream fos = openFileOutput("filename",MODE_APPEND);
			fos.write(content.getBytes());
			fos.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

读的方法:

private String read(){
		try {
			FileInputStream fis = openFileInput("filename");
			byte[] buffer = new byte[fis.available()];
			fis.read(buffer);
			return new String(buffer);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

你可能感兴趣的:(android)