Android : Create and Write data into JSON file and read data from that JSON file

I want code for create a JSON/XML/Text file into res/raw folder and write data into that JSON/XML/Text file in android.If my requirement is wrong then please suggest me with suitable code..Thanks in advance..this is my code..\[code\]package com.example.jsonwork;public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button click = (Button) findViewById(R.id.click); click.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { doJson(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; } public void doJson(){ try { File f = new File( "android.resource://"+this.getPackageName()+"/" + getResources().getString(R.raw.hii)); FileOutputStream out = openFileOutput(f.getName(), MODE_APPEND); OutputStreamWriter osw = new OutputStreamWriter(out); osw.write("Appending String"); osw.flush(); osw.close(); InputStream is = openFileInput(f.getName()); byte[] buffer = new byte[is.available()]; while (is.read(buffer) != -1); String jsontext = new String(buffer); TextView text = (TextView) findViewById(R.id.text); text.setText(jsontext); } catch (Exception e) { TextView text = (TextView) findViewById(R.id.text); text.setText("Error : \n\t"+e.getMessage()); } }}\[/code\]
 
Back
Top