data storage on android device

edited December 2013 in Using Processing

can anyone please counsel me on how to store and reuse data on an android device ??

Answers

  • edited December 2013

    I use this code to check for/create an SD card directory:

    String dirName;
    dirName = "//sdcard//folderName/";
    try {
        File newFile = new File(dirName);
        if (newFile.exists()) {
          println("Directory already exists");
        } 
        else {
          newFile.mkdirs();
          if (newFile.exists() && newFile.isDirectory()) {     
           println("Directory created successfully...");
          }
        }
    }
    catch(Exception e) {
      println("Error creating folder... "); 
    }
    

    ....and this to write files (ready prepared byte array e.g myArray of data):

       String fileName:
       fileName = "myFile";
       try {
          saveBytes(dirName+fileName, myArray);
          println(fileName + " was saved to " + dirName);
        }
        catch(Exception e) {
          println("error while trying to save " + fileName);
        }
    

    ... and this to load it:

    try{    
      loadArray=loadBytes("//sdcard//folderName/"+ fileName);
    }
    catch{
          println("error while trying to load " + fileName);
    }
    

    Mark

Sign In or Register to comment.