Android file Storage (i)

Source: Internet
Author: User

Tag: amp string str protect end CTE New put Contex

Package com.example.sql_file_Input;

Import Java.io.BufferedWriter;
Import Java.io.FileOutputStream;
Import Java.io.OutputStreamWriter;

Import Com.example.sql_file. R

Import android.app.Activity;
Import Android.content.Context;
Import Android.os.Bundle;
Import Android.widget.EditText;

public class Mainactivity extends Activity {

Private EditText edit;

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Edit = Findviewbyid (R.id.edit);
}
@Override
protected void OnDestroy () {
TODO auto-generated Method Stub
Super.ondestroy ();
String Inputtext=edit.gettext (). toString ();
Save (Inputtext);
}
private void Save (String inputtext) {
FileOutputStream Out=null;
BufferedWriter Write=null;
try {
Out=openfileoutput ("Data.txt", context.mode_private);
Write=new BufferedWriter (New OutputStreamWriter (out));
Write.write (Inputtext);
if (write! = null) {
Write.close ();//file must be closed after writing
}
} catch (Exception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
}

Android file Storage (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.