I have some problems with the creation of a file. For instance, I want to create a file on the sdcard and first i want to check whether file exists or not. If file not exist i will create one and write some text in otherwise if it exists i will append it some text.
To copy a file from the connected emulator/device onto the computer, use the following command: adb.exe pull /data/app/<filename> c:\ NOTE When using the adb.exe utility to pull or push files from or into the emulator, ensure that only one AVD is running.
To open the Device Explorer, select View > Tool Windows > Device File Explorer or click the Device File Explorer button in the tool window bar. Select a device from the list. Interact with the device content in the file explorer window: Right-click a file or directory to create a new file or directory.
     String state = Environment.getExternalStorageState();
                if (Environment.MEDIA_MOUNTED.equals(state)) 
                {
                     //SDcard is available
                       File f=new File("/sdcard/test.txt");
                       if (!f.exists()) 
                       {
                        //File does not exists
                        f.createNewFile();
                       }
                      //take your inputstream and write it to your file
                      OutputStream out=new FileOutputStream(f);
                      byte buf[]=new byte[1024];
                      int len;
                      while((len=inputStream.read(buf))>0)
                      out.write(buf,0,len);
                      out.close();
                      inputStream.close();
                      System.out.println("\nFile is created...................................");
                }
Dont forget to add the following permission to manifest
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With