Ways to read and write private files in Android programming _android

Source: Internet
Author: User
Tags sqlite database

This example describes the way to read and write private files in Android programming. Share to everyone for your reference, specific as follows:

A private file is a file that the program itself can read, and other programs do not have permission to access, which is saved in the Data.app. Package. File directory.

The method of writing a file is simpler:

private void WriteFile (string filename, string info) {
 try {
  FileOutputStream fout = openfileoutput (filename, MOD E_private);
  byte[] bytes = Info.getbytes ();
  Fout.write (bytes);
  Fout.close ();
 } catch (Exception err) {
 }
}

This completes the writing of the private file, using the Openfileoutput file when writing a private file.

The private file is written above, and the private file is read below:

private string ReadFile (string filename) {
 try {
  fileinputstream fin = openfileinput (fileName);
  int length = fin.available ()//Get file length
  byte[] bytes = new Byte[length];
  Fin.read (bytes);
  Return encodingutils.getstring (bytes, ENCODING);
 } catch (Exception err) {return
  "";
 }
}

Use "Openfileinput" to read private files!

For more information on Android-related content readers can view the site: "Android file Operation tips Summary", "Android Resource Operation skills Summary", "Android operation XML Data Skills summary", " The activity of Android programming skills summary, "Android operation SQLite Database Skills Summary", "Android operation JSON format Data Skills summary", "Android Database Operation skills Summary", " Android programming development of the SD card operating methods summary, "Android Development introduction and Advanced Course", "Android View Overview" and "Android Control usage Summary"

I hope this article will help you with the Android program.

Related Article

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.