久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <small id='Xb2Z2'></small><noframes id='Xb2Z2'>

    1. <i id='Xb2Z2'><tr id='Xb2Z2'><dt id='Xb2Z2'><q id='Xb2Z2'><span id='Xb2Z2'><b id='Xb2Z2'><form id='Xb2Z2'><ins id='Xb2Z2'></ins><ul id='Xb2Z2'></ul><sub id='Xb2Z2'></sub></form><legend id='Xb2Z2'></legend><bdo id='Xb2Z2'><pre id='Xb2Z2'><center id='Xb2Z2'></center></pre></bdo></b><th id='Xb2Z2'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Xb2Z2'><tfoot id='Xb2Z2'></tfoot><dl id='Xb2Z2'><fieldset id='Xb2Z2'></fieldset></dl></div>
        <bdo id='Xb2Z2'></bdo><ul id='Xb2Z2'></ul>

      <tfoot id='Xb2Z2'></tfoot>
    2. <legend id='Xb2Z2'><style id='Xb2Z2'><dir id='Xb2Z2'><q id='Xb2Z2'></q></dir></style></legend>

      在 Android 的外部存儲中寫入文件

      Write a file in external storage in Android(在 Android 的外部存儲中寫入文件)

      • <legend id='mamDx'><style id='mamDx'><dir id='mamDx'><q id='mamDx'></q></dir></style></legend>

            <tfoot id='mamDx'></tfoot>
              <tbody id='mamDx'></tbody>

              <small id='mamDx'></small><noframes id='mamDx'>

                <bdo id='mamDx'></bdo><ul id='mamDx'></ul>

                <i id='mamDx'><tr id='mamDx'><dt id='mamDx'><q id='mamDx'><span id='mamDx'><b id='mamDx'><form id='mamDx'><ins id='mamDx'></ins><ul id='mamDx'></ul><sub id='mamDx'></sub></form><legend id='mamDx'></legend><bdo id='mamDx'><pre id='mamDx'><center id='mamDx'></center></pre></bdo></b><th id='mamDx'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='mamDx'><tfoot id='mamDx'></tfoot><dl id='mamDx'><fieldset id='mamDx'></fieldset></dl></div>

                本文介紹了在 Android 的外部存儲中寫入文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習吧!

                問題描述

                我想在外部存儲 sdCard 中創(chuàng)建一個文件并寫入它.我已經(jīng)通過互聯(lián)網(wǎng)搜索并嘗試但沒有得到結(jié)果,我也在 Android Manifest 文件中添加了權(quán)限,我正在模擬器上執(zhí)行此操作,我我正在嘗試以下代碼并得到一個 ERRR", "Could not create file".

                I want to create a file in external storage sdCard and write to it.I have searched through internet and try but not getting the result,I have added permission in Android Manifest file as well,I am doing this on Emulator,I am trying the following code and getting a ERRR", "Could not create file".

                btnWriteSDFile = (Button) findViewById(R.id.btnWriteSDFile);
                btnWriteSDFile.setOnClickListener(new OnClickListener() {
                    //private Throwable e;
                
                    @Override
                    public void onClick(View v) {
                        // write on SD card file data from the text box
                        try {
                            File myFile = new File("/sdcard/mysdfile.txt");
                            myFile.createNewFile();
                            FileOutputStream fOut = new FileOutputStream(myFile);
                            OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
                            myOutWriter.append(txtData.getText());
                            myOutWriter.close();
                            fOut.close();
                
                        } catch (Exception e) {
                              Log.e("ERRR", "Could not create file",e);
                        } 
                    }// onClick
                }); // btnWriteSDFile
                

                推薦答案

                你也可以用這段代碼來做到這一點.

                You can do this with this code also.

                 public class WriteSDCard extends Activity {
                
                 private static final String TAG = "MEDIA";
                 private TextView tv;
                
                  /** Called when the activity is first created. */
                @Override
                 public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.main);     
                    tv = (TextView) findViewById(R.id.TextView01);
                    checkExternalMedia();
                    writeToSDFile();
                    readRaw();
                 }
                
                /** Method to check whether external media available and writable. This is adapted from
                   http://developer.android.com/guide/topics/data/data-storage.html#filesExternal */
                
                 private void checkExternalMedia(){
                      boolean mExternalStorageAvailable = false;
                    boolean mExternalStorageWriteable = false;
                    String state = Environment.getExternalStorageState();
                
                    if (Environment.MEDIA_MOUNTED.equals(state)) {
                        // Can read and write the media
                        mExternalStorageAvailable = mExternalStorageWriteable = true;
                    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
                        // Can only read the media
                        mExternalStorageAvailable = true;
                        mExternalStorageWriteable = false;
                    } else {
                        // Can't read or write
                        mExternalStorageAvailable = mExternalStorageWriteable = false;
                    }   
                    tv.append("
                
                External Media: readable="
                            +mExternalStorageAvailable+" writable="+mExternalStorageWriteable);
                }
                
                /** Method to write ascii text characters to file on SD card. Note that you must add a 
                   WRITE_EXTERNAL_STORAGE permission to the manifest file or this method will throw
                   a FileNotFound Exception because you won't have write permission. */
                
                private void writeToSDFile(){
                
                    // Find the root of the external storage.
                    // See http://developer.android.com/guide/topics/data/data-  storage.html#filesExternal
                
                    File root = android.os.Environment.getExternalStorageDirectory(); 
                    tv.append("
                External file system root: "+root);
                
                    // See http://stackoverflow.com/questions/3551821/android-write-to-sd-card-folder
                
                    File dir = new File (root.getAbsolutePath() + "/download");
                    dir.mkdirs();
                    File file = new File(dir, "myData.txt");
                
                    try {
                        FileOutputStream f = new FileOutputStream(file);
                        PrintWriter pw = new PrintWriter(f);
                        pw.println("Hi , How are you");
                        pw.println("Hello");
                        pw.flush();
                        pw.close();
                        f.close();
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                        Log.i(TAG, "******* File not found. Did you" +
                                " add a WRITE_EXTERNAL_STORAGE permission to the   manifest?");
                    } catch (IOException e) {
                        e.printStackTrace();
                    }   
                    tv.append("
                
                File written to "+file);
                }
                
                /** Method to read in a text file placed in the res/raw directory of the application. The
                  method reads in all lines of the file sequentially. */
                
                private void readRaw(){
                    tv.append("
                Data read from res/raw/textfile.txt:");
                    InputStream is = this.getResources().openRawResource(R.raw.textfile);
                    InputStreamReader isr = new InputStreamReader(is);
                    BufferedReader br = new BufferedReader(isr, 8192);    // 2nd arg is buffer size
                
                    // More efficient (less readable) implementation of above is the composite expression
                    /*BufferedReader br = new BufferedReader(new InputStreamReader(
                            this.getResources().openRawResource(R.raw.textfile)), 8192);*/
                
                    try {
                        String test;    
                        while (true){               
                            test = br.readLine();   
                            // readLine() returns null if no more lines in the file
                            if(test == null) break;
                            tv.append("
                "+"    "+test);
                        }
                        isr.close();
                        is.close();
                        br.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    tv.append("
                
                That is all");
                }
                }
                

                這篇關(guān)于在 Android 的外部存儲中寫入文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                Get user#39;s current location using GPS(使用 GPS 獲取用戶的當前位置)
                IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                How to detect Location Provider ? GPS or Network Provider(如何檢測位置提供者?GPS 或網(wǎng)絡(luò)提供商)
                Get current location during app launch(在應(yīng)用啟動期間獲取當前位置)
                locationManager.getLastKnownLocation() return null(locationManager.getLastKnownLocation() 返回 null)

              • <i id='jMuKe'><tr id='jMuKe'><dt id='jMuKe'><q id='jMuKe'><span id='jMuKe'><b id='jMuKe'><form id='jMuKe'><ins id='jMuKe'></ins><ul id='jMuKe'></ul><sub id='jMuKe'></sub></form><legend id='jMuKe'></legend><bdo id='jMuKe'><pre id='jMuKe'><center id='jMuKe'></center></pre></bdo></b><th id='jMuKe'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='jMuKe'><tfoot id='jMuKe'></tfoot><dl id='jMuKe'><fieldset id='jMuKe'></fieldset></dl></div>
                  <tbody id='jMuKe'></tbody>

                    <small id='jMuKe'></small><noframes id='jMuKe'>

                      <tfoot id='jMuKe'></tfoot>

                      • <bdo id='jMuKe'></bdo><ul id='jMuKe'></ul>

                          <legend id='jMuKe'><style id='jMuKe'><dir id='jMuKe'><q id='jMuKe'></q></dir></style></legend>
                        1. 主站蜘蛛池模板: 免费在线观看成年人视频 | 久久99精品久久久久久国产越南 | 中文字幕蜜臀av | 日韩中文在线 | 国产精品久久性 | 免费人成激情视频在线观看冫 | 国产精品自拍av | 午夜欧美a级理论片915影院 | 亚洲一区二区中文字幕 | 中文字幕视频在线观看 | 国产精品一区二区三区在线 | 在线播放一区二区三区 | 米奇狠狠鲁 | 91精品久久久久久久久久小网站 | 国产高清精品一区二区三区 | 国产欧美一级二级三级在线视频 | 91精品国产91久久综合桃花 | 国产日韩精品在线 | 国产欧美日韩视频 | 综合久久久 | 日本特黄a级高清免费大片 国产精品久久性 | 美女露尿口视频 | 亚洲视频在线观看一区二区三区 | 国产一二区在线 | 一级黄色片网站 | 日本 欧美 三级 高清 视频 | 欧美日韩专区 | 成人免费在线观看 | 日韩高清一区 | 天堂在线www| 久久99精品久久久久久秒播九色 | 91精品国产欧美一区二区成人 | 亚洲午夜视频 | www免费视频 | 在线观看国产wwwa级羞羞视频 | 99reav | 九九热在线视频免费观看 | 精品视频一区二区 | av在线一区二区 | 久久国产美女视频 | 欧美精品一区二区三区在线播放 |