2013年9月17日 星期二

Check existency and write file in Android


     File file = new File(filePath);  
     if (!file.exists()){
         Log.d(TAG, "Create " + filePath);
         try {    
          file.createNewFile();
          OutputStreamWriter pswtr = new OutputStreamWriter(new FileOutputStream(file));
             for (int i= 0;i < 8; i++) {
                   pswtr.write("hotkey"+i+"=com.android.settings\n");
             }      
                pswtr.close();
         }
         catch (FileNotFoundException e) {
             Log.e(TAG , "Got exception " + e);
         }
         catch (IOException e) {
             Log.e(TAG , "Got exception " + e);
         }             
     }

沒有留言:

張貼留言