Maid®Why? £° Android? Why?®SD success

Source: Internet
Author: User

Micro?

° Á²» É ¤ £ £*ó û ²» É × £ £ **************************************************** ¡ª ¡Î ° áço


*

Elasticsearch images» rööööw, µ« Ç â n µ µäê ¾ Ç ç'æ '~~~~~~~~äzäzä£;{'' then '{µää ä¼ {'ó Ð ó Ð Ó Ò» ¨ Ö Ç when 'taobao' then ü üräzäzäzäz?£;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Î Ò schemaväsdsard 'hangzhou' has been written into £.


WHY» Why? SDCard? Why? £m.Environment À àÎ ª Ò Ç ***************

VcmRlcj0 = "1" width = "800" cellspacing = "1" cellpadding = "1">
Public static File getDataDirectory () » 'N' limit Android limit  µädata limit ä?margin limit µää  limit
Public static File getDownloadCacheDirectory () » N. Micron Android Download/Cache äúè {µää  ¼
Public static File getExternalStorageDirectory () » 'N' limit Android íâ ² comment 'clerk' limit comment 'sdcard µää â limit
Public static String getExternalStorageState () » 'N' limit Android íâ ² limit 'hangzhou' limit µä±ç° × 'limit
Public static File getRootDirectory () » 'N' limit Android limit  µäroot limit ä¼ limit µää  limit

£Ózón= ¿

String MEDIA_MOUNTED Μ±ç° Android maid comment'
String MEDIA_MOUNTED_READ_ONLY Μ±ç° Android µäíâ ² comment 'hangzhou' ~~ö» máá

¶ Þ ¡Î Ç» ú» ¶ ¼ Ð 'ú ú× ¢ Ê íà Á áë

 à æ çres/layout/activity_main.xml ² ¾ Ö öî ä¼ £°

    
      
      
  
 

Ú úandroidmanifest. xml Î ä¼ Ö öð × ² ás

 
    
    
    
        
                          
                                  
               
              
 

Ï Â Ã Ê çmainactivity. java ö÷ ½ ç?ä ä¼ £ £°

public class MainActivity extends Activity implements OnClickListener {private static final String FILE_NAME = "text.txt";private Button write;private Button read;EditText edit;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);findViews();}private void findViews() {edit = (EditText) findViewById(R.id.edit);write = (Button) findViewById(R.id.write);read = (Button) findViewById(R.id.read);write.setOnClickListener(this);read.setOnClickListener(this);}public void onClick(View v) {switch (v.getId()) {case R.id.write:// ÏÈÅжÏÊÇ·ñÓÐSDCardif (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {String content = edit.getText().toString();try {// »ñÈ¡SDcard·¾¶File dir = Environment.getExternalStorageDirectory();// »ñÈ¡SDcard·¾¶ÃûµÄ¾ø¶Ô·¾¶Ãû×Ö·û´¡£eg:/mnt/sdcard String sdcardPath = dir.getAbsolutePath();Toast.makeText(MainActivity.this,"Ŀ¼Ϊ£º" + sdcardPath, Toast.LENGTH_SHORT).show();File file = new File(dir, FILE_NAME);// ÒÔÖ¸¶¨Îļþ´´½¨RandomAccessFile¶ÔÏóRandomAccessFile raf = new RandomAccessFile(file, "rw");// ½«Îļþ¼Ç¼ָÕëÒÆ¶¯×îºóraf.seek(file.length());// Êä³öÎļþÄÚÈÝraf.write(content.getBytes());raf.close();} catch (Exception e) {}}break;case R.id.read:if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {// »ñÈ¡SDcard·¾¶StringBuilder sb = new StringBuilder();try {File dir = Environment.getExternalStorageDirectory();File file = new File(dir, FILE_NAME);InputStream inputStream = new FileInputStream(file);int len = 0;byte[] buffer = new byte[1024];while ((len = inputStream.read(buffer)) != -1) {sb.append(new String(buffer, 0, len));}Toast.makeText(MainActivity.this,"ƒÈÈÝΪ£º" + sb.toString(), Toast.LENGTH_SHORT).show();// ¹Ø±ÕÁ÷inputStream.close();} catch (Exception e) {}}}}}

Â Ã Ç Ð ½ á £ £°



± 00000000² µ00000000â À 0000£00000000» consumed» 'ó shall have £m ¡


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.