久久久久久久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 的外部存儲中寫入文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我想在外部存儲 sdCard 中創建一個文件并寫入它.我已經通過互聯網搜索并嘗試但沒有得到結果,我也在 Android Manifest 文件中添加了權限,我正在模擬器上執行此操作,我我正在嘗試以下代碼并得到一個 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");
                }
                }
                

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

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

                相關文檔推薦

                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 或網絡提供商)
                Get current location during app launch(在應用啟動期間獲取當前位置)
                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. 主站蜘蛛池模板: 亚洲狠狠 | 人人干人人艹 | 日日骚视频 | 免费观看成人性生生活片 | 亚洲精品乱码久久久久久久久久 | 亚洲精品第一国产综合野 | 一本一道久久a久久精品蜜桃 | 日本在线黄色 | 1级毛片| 99久久精品一区二区成人 | 国产一区二区三区在线免费 | 天天爱爱网 | 老司机深夜福利网站 | 欧美中文字幕一区二区三区亚洲 | 国产精品免费福利 | 精品久久网| 狠狠的操| 国产在线h| 怡红院免费的全部视频 | 国产黄色在线观看 | 羞羞视频一区二区 | 久久精品69 | 久久精品亚洲 | 日韩中文字幕一区二区三区 | 中文在线a在线 | 欧美一级黑人aaaaaaa做受 | 国产精品免费一区二区三区四区 | 久久国产精品精品国产色婷婷 | 亚洲精品乱码久久久久久按摩观 | 精品真实国产乱文在线 | 中国一级特黄真人毛片 | 狠狠狠| 91麻豆精品国产91久久久更新资源速度超快 | 久久av综合 | av电影手机在线看 | 日韩欧美国产精品一区二区三区 | 国产日韩欧美一区二区 | 免费一区在线 | 欧美人成在线视频 | 天天干人人 | 99在线资源 |