Creating a new file on an SD card

Creating a new file on an SD card

By : Shaniqua Ford
Date : November 18 2020, 07:00 PM
wish helps you EDIT: I tested your code and it works. You need read write permissions!
Add these to the manifest
code :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
public void checkWritePermissions(){
    // Here, thisActivity is the current activity
    if (ContextCompat.checkSelfPermission(this,
            != PackageManager.PERMISSION_GRANTED) {

        // Permission is not granted
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            // Show an explanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.
        } else {
            // No explanation needed; request the permission
                    new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); //1 is the requestCode
    } else {
        // Permission has already been granted
        writeFile(); //Or maybe return a bool value, true or false
public void onRequestPermissionsResult(int requestCode,
                                       String[] permissions, int[] grantResults) {
    switch (requestCode) {
        case 1: { //CODE 1
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // permission was granted, yay! Do the
                // WRITE_EXTERNAL_STORAGE-related task you need to do.
                //Continue and write the file
            } else {
                // permission denied, boo! Disable the
                // functionality that depends on this permission.
                //Maybe display a message or something

        // other 'case' lines to check for other
        // permissions this app might request.
 //Lets make a new DIR
 if (!file.getParentFile().exists()){

    new AlertDialog.Builder(this).setTitle("File Created").setMessage("File successfully created!").show();

Share : facebook icon twitter icon
Creating a file on the SD-Card in android

Creating a file on the SD-Card in android

By : user2274375
Date : March 29 2020, 07:55 AM
I wish this helpful for you Well if you need compatibility with API level 7 and lower, use getExternalStorageDirectory() method. Also note that staring from API level 4 you have to request permission to write onto SD card:
code :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Problems deleting and creating file on SD card

Problems deleting and creating file on SD card

By : Franc Adamič
Date : March 29 2020, 07:55 AM
Does that help I realised the reason it wasn't saving sometimes was because I was taking the SD card out of the phone before it had the chance to save.
Creating and Writing a file to the SD card...File Not Found exception is coming

Creating and Writing a file to the SD card...File Not Found exception is coming

By : Nagato
Date : March 29 2020, 07:55 AM
To fix this issue I'm trying to write a file on SD Card but I'm unable to do it. Can you help me debug the code?
code :
File mydir = new File(Environment.getExternalStorageDirectory() + "/" +directoryName); //Creating an internal dir; 

    File fileWithinMyDir = new File(mydir, fileName+".pList"); //Getting a file within the dir. 
    FileOutputStream fos = new FileOutputStream(fileWithinMyDir);
creating a txt file on sd card but i cant find it

creating a txt file on sd card but i cant find it

By : ka.e
Date : March 29 2020, 07:55 AM
With these it helps getExternalStorageDirectory() does not necessary return /sdcard directory. See here Environment.getExternalStorageDirectory does not return the path to the removable storage
how to place Mat-Card Mat-card-action at bottom of card when we are creating cards dynamically

how to place Mat-Card Mat-card-action at bottom of card when we are creating cards dynamically

By : Benji Hammond
Date : March 29 2020, 07:55 AM
should help you out , Add in stylesheet:
code :
  flex-direction: column;

.mat-card-header {
  flex-shrink: 0;

  flex-grow: 1;
  overflow: auto;
Related Posts Related Posts :
  • doubt on private members and Methods
  • How do I check if output stream of a socket is closed?
  • Is there a clean cut way of adding NOP records to an AFP file using Java?
  • Move multiple BufferedImage in Java2D?
  • how to learn Drools or another rule engine fast
  • Date Sorting - Latest to Oldest
  • unable to add objects to saved collection in GAE using JDO
  • Spring, Hibernate, Blob lazy loading
  • Including Applet in JSP page
  • Original object is also changed when values of cloned object are changed
  • Drag and drop + custom drawing in Android
  • Creating a time series with jfreechart
  • Hibernate Criteria: Perform JOIN in Subquery/DetachedCriteria
  • How to check if my string is equal to null?
  • Connect two client sockets
  • How to reference a .dll from a .jar file
  • Invoke web-services in JSF
  • servlet connection to DB
  • Can I un-assign (clear) all fields of an instance?
  • Java parsing XML document gives "Content not allowed in prolog." error
  • Deploy Play! application as executable jar
  • Castor: how to map a simple list of strings?
  • Hibernate Transient Extends problem
  • Posting a JSON array to webservice in Android
  • How to search for duplicate values in a huge text file having around Half Million records
  • Easy way to get a test file into JUnit
  • cast across classloader?
  • Image manipulation
  • Java - JPA - Generators - @SequenceGenerator
  • What's a good Java-based Master-Slave communication mechanism?
  • Design Help/Suggestion required
  • NullPointerException in com.sun.tools.jxc.SchemaGenTask
  • time required to finish the multithreaded program?
  • Traditional IO vs memory-mapped
  • Using StringBuilder to process csv files to save heap space
  • Response Time is different for mulitiple execution of the application with the same request Performance problem
  • Java - Weblogic - JMX : request available free memory on all servers
  • Error: Can't find common super class of
  • JNI problem when calling a native library that loads another native library
  • calling Stanford POS Tagger maxentTagger from java program
  • Notification framework for java
  • hide keyboard in android?
  • Alternative of JPA
  • How to get Java XP Look and Feel
  • Remote JMS connection still using localhost
  • Java NoClassDefFoundError
  • Is O(N!*N) an acceptable big oh complexity class or do I remove the constant and just say O(N!)?
  • Java File URI error?
  • Using an interface as a constructor parameter in Java?
  • Add additional path to exec-maven-plugin
  • Natural Language parsing of an appointment?
  • Java: How to tell which fontconfig file my system is currently using?
  • How to create notification icon badge on Android apps (like iPhone)
  • Interfaces with hibernate annotations
  • Getting ConnectionTimeoutException with the host did not accept the connection within timeout
  • How to get all property names of a Groovy class?
  • Java Netscape LDAP Remove One Attribute
  • A simple two column layout with Swing
  • Making a Linked list using Generics
  • how to handle result set data
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk