"Android Interview book" Study Notes (Chapter Fifth: file storage)

Source: Internet
Author: User

What file storage technology does the Android SDK support?

Sharedpreferences, stream file storage, XML semi-structured storage, JSON storage, database, third aspect to the object database.


How do I access key-value type of data using Shardpreferences?

Instantiate the Sharedpreferences object (first step) sharedpreferences mysharedpreferences= getsharedpreferences ("Test", Activity.mode_ PRIVATE); Instantiate the Sharedpreferences.editor object (step two) Sharedpreferences.editor Editor = Mysharedpreferences.edit (); Save the data editor.putstring ("name", "Karl") with putstring method; Editor.putstring ("Habit", "sleep"); Submit Current Data editor.commit ();
Similarly, an Sharedpreferences object is instantiated before reading sharedpreferences data sharedpreferencessharedpreferences= getsharedpreferences ( "Test", activity.mode_private); Use the GetString method to get value, note that the 2nd parameter is the default value of String name =sharedpreferences.getstring ("name", "" "); String habit =sharedpreferences.getstring ("Habit", "" "); Display information using the Toast Information prompt box

In which directory is the sharedpreferences saved data file stored? Can I read these data files without using sharedpreferences?

File storage path is Data/data/packagename/shared_prefs

You can read files directly with a file stream.



Sharedpreferences can I save the data on my SD card?

You can modify the file save path with Java reflection technology.


Sharedpreferences can I save image data?

To convert an image to binary data:

Public byte[] Getbitmapbyte (Bitmap Bitmap) {bytearrayoutputstream out = new Bytearrayoutputstream ();      Bitmap.compress (Bitmap.CompressFormat.JPEG, N, out);          try {out.flush ();      Out.close ();      } catch (IOException e) {e.printstacktrace ();  } return Out.tobytearray (); }

Read:

    1. Public Bitmap getbitmapfrombyte (byte[] temp) {if (temp! = null) {Bitmap Bitmap = Bitmapfactory.decodebytearra          Y (temp, 0, temp.length);      return bitmap;      }else{return null; }  }


How do I implement the Settings page via preferencesactivity?

Http://www.jb51.net/article/31915.htm


Preferenceactivity What is the default file name for saving data? How do I change it?

Packagename_preferences.xml.

Modified with the Preferencemanager.getsharedpreferencesname method.


What does the Android SDK support for getting file input and output streams?

1:inputstream and OutputStream Way.

http://blog.csdn.net/ztp800201/article/details/7322110

2:context.openfileoutput and Context.openfileinput objects.

Http://blog.sina.com.cn/s/blog_6e5195850100zssn.html


What is the SAX engine's process of parsing XML documents?

Initialize--start processing each XML element--Process the elements--finish the file, finish finishing the work--Save the text of the XML element


How do I convert an XML file to a Java object?

http://showlike.iteye.com/blog/1050843







Android Interview Cookbook study notes (fifth: file storage)

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.